diff --git a/app/api/generate/[fileName]/route.ts b/app/api/generate/[ide]/[framework]/[fileName]/route.ts similarity index 85% rename from app/api/generate/[fileName]/route.ts rename to app/api/generate/[ide]/[framework]/[fileName]/route.ts index a628ed3..97dc025 100644 --- a/app/api/generate/[fileName]/route.ts +++ b/app/api/generate/[ide]/[framework]/[fileName]/route.ts @@ -17,18 +17,31 @@ function mapOutputFileToTemplateType(outputFile: string): string { export async function POST( request: NextRequest, - { params }: { params: Promise<{ fileName: string }> } + { params }: { params: { ide: string; framework: string; fileName: string } } ) { try { - const { fileName } = await params + const { ide, framework, fileName } = params const body = await request.json() const responses: WizardResponses = body // Determine template configuration based on the request let templateConfig + const frameworkFromPath = framework && !['general', 'none', 'undefined'].includes(framework) + ? framework + : undefined + + if (ide) { + const templateKeyFromParams: TemplateKey = { + ide, + templateType: mapOutputFileToTemplateType(fileName), + framework: frameworkFromPath + } + templateConfig = getTemplateConfig(templateKeyFromParams) + } + // Check if this is a combination-based request - if (responses.preferredIde && responses.outputFile) { + if (!templateConfig && responses.preferredIde && responses.outputFile) { const templateKey: TemplateKey = { ide: responses.preferredIde, templateType: mapOutputFileToTemplateType(responses.outputFile), @@ -109,4 +122,4 @@ export async function POST( { status: 500 } ) } -} \ No newline at end of file +} diff --git a/components/instructions-wizard.tsx b/components/instructions-wizard.tsx index 7b7364c..30cada2 100644 --- a/components/instructions-wizard.tsx +++ b/components/instructions-wizard.tsx @@ -593,14 +593,21 @@ export function InstructionsWizard({ onClose }: InstructionsWizardProps) { // Call the API to generate the instructions file if (questionsAndAnswers.outputFile) { + const ideSegment = questionsAndAnswers.preferredIde ?? 'unknown' + const frameworkSegment = questionsAndAnswers.frameworkSelection ?? 'general' + const fileNameSegment = questionsAndAnswers.outputFile + try { - const response = await fetch(`/api/generate/${questionsAndAnswers.outputFile}`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(questionsAndAnswers), - }) + const response = await fetch( + `/api/generate/${encodeURIComponent(ideSegment)}/${encodeURIComponent(frameworkSegment)}/${encodeURIComponent(fileNameSegment)}`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(questionsAndAnswers), + } + ) if (response.ok) { const data = await response.json()