diff --git a/src/build/functions/server.ts b/src/build/functions/server.ts index bd38a82162..b3cb217989 100644 --- a/src/build/functions/server.ts +++ b/src/build/functions/server.ts @@ -100,12 +100,26 @@ const applyTemplateVariables = (template: string, variables: Record { + return route + .replace(/\[\[\.\.\.(\w+)]]/g, ':$1*') // [[...slug]] -> :slug* + .replace(/\[\.{3}(\w+)]/g, ':$1+') // [...slug] -> :slug+ + .replace(/\[(\w+)]/g, ':$1') // [id] -> :id +} + /** Get's the content of the handler file that will be written to the lambda */ const getHandlerFile = async (ctx: PluginContext): Promise => { const templatesDir = join(ctx.pluginDir, 'dist/build/templates') + const routesManifest = await ctx.getRoutesManifest() + const routes = [...routesManifest.staticRoutes, ...routesManifest.dynamicRoutes] + .map((route) => transformRoutePattern(route.page)) + .join("','") + const templateVariables: Record = { '{{useRegionalBlobs}}': ctx.useRegionalBlobs.toString(), + '{{paths}}': routes, } // In this case it is a monorepo and we need to use a own template for it // as we have to change the process working directory diff --git a/src/build/templates/handler.tmpl.js b/src/build/templates/handler.tmpl.js index 0b10bcd902..1a089cb09f 100644 --- a/src/build/templates/handler.tmpl.js +++ b/src/build/templates/handler.tmpl.js @@ -44,6 +44,6 @@ export default async function handler(req, context) { } export const config = { - path: '/*', + path: ['{{paths}}'], preferStatic: true, }