Skip to content

Commit be5fdab

Browse files
authored
Merge pull request #3 from spivx/dev/change-route
Dev/change route
2 parents 8001b2d + 829eb4b commit be5fdab

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

app/api/generate/[fileName]/route.ts renamed to app/api/generate/[ide]/[framework]/[fileName]/route.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,31 @@ function mapOutputFileToTemplateType(outputFile: string): string {
1717

1818
export async function POST(
1919
request: NextRequest,
20-
{ params }: { params: Promise<{ fileName: string }> }
20+
{ params }: { params: { ide: string; framework: string; fileName: string } }
2121
) {
2222
try {
23-
const { fileName } = await params
23+
const { ide, framework, fileName } = params
2424
const body = await request.json()
2525
const responses: WizardResponses = body
2626

2727
// Determine template configuration based on the request
2828
let templateConfig
2929

30+
const frameworkFromPath = framework && !['general', 'none', 'undefined'].includes(framework)
31+
? framework
32+
: undefined
33+
34+
if (ide) {
35+
const templateKeyFromParams: TemplateKey = {
36+
ide,
37+
templateType: mapOutputFileToTemplateType(fileName),
38+
framework: frameworkFromPath
39+
}
40+
templateConfig = getTemplateConfig(templateKeyFromParams)
41+
}
42+
3043
// Check if this is a combination-based request
31-
if (responses.preferredIde && responses.outputFile) {
44+
if (!templateConfig && responses.preferredIde && responses.outputFile) {
3245
const templateKey: TemplateKey = {
3346
ide: responses.preferredIde,
3447
templateType: mapOutputFileToTemplateType(responses.outputFile),
@@ -109,4 +122,4 @@ export async function POST(
109122
{ status: 500 }
110123
)
111124
}
112-
}
125+
}

components/instructions-wizard.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -593,14 +593,21 @@ export function InstructionsWizard({ onClose }: InstructionsWizardProps) {
593593

594594
// Call the API to generate the instructions file
595595
if (questionsAndAnswers.outputFile) {
596+
const ideSegment = questionsAndAnswers.preferredIde ?? 'unknown'
597+
const frameworkSegment = questionsAndAnswers.frameworkSelection ?? 'general'
598+
const fileNameSegment = questionsAndAnswers.outputFile
599+
596600
try {
597-
const response = await fetch(`/api/generate/${questionsAndAnswers.outputFile}`, {
598-
method: 'POST',
599-
headers: {
600-
'Content-Type': 'application/json',
601-
},
602-
body: JSON.stringify(questionsAndAnswers),
603-
})
601+
const response = await fetch(
602+
`/api/generate/${encodeURIComponent(ideSegment)}/${encodeURIComponent(frameworkSegment)}/${encodeURIComponent(fileNameSegment)}`,
603+
{
604+
method: 'POST',
605+
headers: {
606+
'Content-Type': 'application/json',
607+
},
608+
body: JSON.stringify(questionsAndAnswers),
609+
}
610+
)
604611

605612
if (response.ok) {
606613
const data = await response.json()

0 commit comments

Comments
 (0)