From 75cda48e9fd0ca9a3480502ca7cb2c0062e446eb Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Mon, 5 Jun 2023 13:45:35 +0200 Subject: [PATCH 1/2] chore: add repro test --- cypress/e2e/default/api.cy.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cypress/e2e/default/api.cy.ts b/cypress/e2e/default/api.cy.ts index b0b24b9b4b..95f420bf92 100644 --- a/cypress/e2e/default/api.cy.ts +++ b/cypress/e2e/default/api.cy.ts @@ -6,6 +6,14 @@ describe('API routes', () => { }) }) +describe('Dynamic API routes', () => { + it('are bundled correctly', () => { + cy.request('/api/shows/1').then((response) => { + expect(response.status).to.equal(200) + }) + }) +}) + describe('Extended API routes', () => { it('returns HTTP 202 Accepted for background route', () => { cy.request('/api/hello-background').then((response) => { From d19f422e1f5f239c502c2e07353cb3c8f08a577b Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Mon, 5 Jun 2023 14:01:34 +0200 Subject: [PATCH 2/2] fix: include files that include [] --- packages/runtime/src/helpers/config.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/runtime/src/helpers/config.ts b/packages/runtime/src/helpers/config.ts index 596a610dec..42198606f9 100644 --- a/packages/runtime/src/helpers/config.ts +++ b/packages/runtime/src/helpers/config.ts @@ -96,6 +96,12 @@ export const hasManuallyAddedModule = ({ ) /* eslint-enable camelcase */ +/** + * Transforms `/api/shows/[id].js` into `/api/shows/*id*.js`, + * so that the file `[id].js` is matched correctly. + */ +const escapeGlob = (path: string) => path.replace(/\[/g, '*').replace(/]/g, '*') + export const configureHandlerFunctions = async ({ netlifyConfig, publish, @@ -173,7 +179,7 @@ export const configureHandlerFunctions = async ({ netlifyConfig.functions[functionName] ||= { included_files: [] } netlifyConfig.functions[functionName].node_bundler = 'none' netlifyConfig.functions[functionName].included_files ||= [] - netlifyConfig.functions[functionName].included_files.push(...includedFiles) + netlifyConfig.functions[functionName].included_files.push(...includedFiles.map(escapeGlob)) } } else { configureFunction('_api_*')