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) => { 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_*')