Skip to content

Commit

Permalink
fix: respect excludedPattern defined in netlify.toml (#6533)
Browse files Browse the repository at this point in the history
* chore: write repro

* fix: check excluded_patterns both for function and for route
  • Loading branch information
Skn0tt committed May 9, 2024
1 parent 9eab9f4 commit 1729ef0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib/edge-functions/registry.ts
Expand Up @@ -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
}

Expand Down
40 changes: 40 additions & 0 deletions tests/integration/commands/dev/dev-miscellaneous.test.js
Expand Up @@ -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'
Expand Down

2 comments on commit 1729ef0

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,347
  • Package size: 312 MB
  • Number of ts-expect-error directives: 997

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,347
  • Package size: 312 MB
  • Number of ts-expect-error directives: 997

Please sign in to comment.