diff --git a/src/lib/edge-functions/registry.ts b/src/lib/edge-functions/registry.ts index 9cee9cdd28e..a736431f532 100644 --- a/src/lib/edge-functions/registry.ts +++ b/src/lib/edge-functions/registry.ts @@ -436,11 +436,15 @@ export class EdgeFunctionsRegistry { return } - const isExcluded = this.manifest?.function_config[route.function]?.excluded_patterns?.some((pattern) => + const isExcludedForFunction = this.manifest?.function_config[route.function]?.excluded_patterns?.some((pattern) => new RegExp(pattern).test(urlPath), ) + if (isExcludedForFunction) { + return + } - if (isExcluded) { + const isExcludedForRoute = route.excluded_patterns.some((pattern) => new RegExp(pattern).test(urlPath)) + if (isExcludedForRoute) { return } diff --git a/tests/integration/commands/dev/dev-miscellaneous.test.js b/tests/integration/commands/dev/dev-miscellaneous.test.js index ba6f03dbb07..14ccc1e204c 100644 --- a/tests/integration/commands/dev/dev-miscellaneous.test.js +++ b/tests/integration/commands/dev/dev-miscellaneous.test.js @@ -933,6 +933,46 @@ describe.concurrent('commands/dev-miscellaneous', () => { }) }) + test('should respect excluded paths specified in TOML', async (t) => { + await withSiteBuilder(t, async (builder) => { + const publicDir = 'public' + builder + .withNetlifyToml({ + config: { + build: { + publish: publicDir, + edge_functions: 'netlify/edge-functions', + }, + edge_functions: [ + { + function: 'hello', + path: '/*', + excludedPath: '/static/*', + }, + ], + }, + }) + .withEdgeFunction({ + handler: () => new Response('Hello world'), + name: 'hello', + }) + + await builder.build() + + await withDevServer({ cwd: builder.directory }, async ({ port }) => { + const [res1, res2] = await Promise.all([ + fetch(`http://localhost:${port}/foo`), + fetch(`http://localhost:${port}/static/foo`), + ]) + + t.expect(res1.status).toBe(200) + t.expect(await res1.text()).toEqual('Hello world') + + t.expect(res2.status).toBe(404) + }) + }) + }) + test('should respect in-source configuration from internal edge functions', async (t) => { await withSiteBuilder(t, async (builder) => { const publicDir = 'public'