diff --git a/src/lib/functions/form-submissions-handler.mjs b/src/lib/functions/form-submissions-handler.mjs index 8c5f5169483..b31605e476c 100644 --- a/src/lib/functions/form-submissions-handler.mjs +++ b/src/lib/functions/form-submissions-handler.mjs @@ -29,7 +29,12 @@ const getFormHandler = function ({ functionsRegistry }) { export const createFormSubmissionHandler = function ({ functionsRegistry, siteUrl }) { return async function formSubmissionHandler(req, res, next) { - if (req.url.startsWith('/.netlify/') || req.method !== 'POST') return next() + if ( + req.url.startsWith('/.netlify/') || + req.method !== 'POST' || + (await functionsRegistry.getFunctionForURLPath(req.url, req.method)) + ) + return next() const fakeRequest = new Readable({ read() { diff --git a/tests/integration/commands/dev/v2-api.test.ts b/tests/integration/commands/dev/v2-api.test.ts index 8854a8d5e6d..78c010c181a 100644 --- a/tests/integration/commands/dev/v2-api.test.ts +++ b/tests/integration/commands/dev/v2-api.test.ts @@ -112,6 +112,12 @@ describe.runIf(gte(version, '18.13.0'))('v2 api', () => { expect(await response.text()).toBe(`With literal path: ${url}`) }) + test('doesnt run form logic on paths matching function', async ({ devServer }) => { + const url = `http://localhost:${devServer.port}/products` + await fetch(url, { method: 'POST' }) + expect(devServer.output).not.toContain("Missing form submission function handler") + }) + test('supports custom URLs with method matching', async ({ devServer }) => { const url = `http://localhost:${devServer.port}/products/really-bad-product` const response = await fetch(url, { method: 'DELETE' })