Skip to content

Commit

Permalink
Merge branch 'main' into feat/functions-v2-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas authored Oct 9, 2023
2 parents 0999308 + 8183fd0 commit a4887e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib/functions/form-submissions-handler.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/commands/dev/v2-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ describe.runIf(gte(version, '18.13.0'))('v2 api', () => {
expect(await response.text()).toBe(`With literal path: ${url}`)
})

test<FixtureTestContext>('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<FixtureTestContext>('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' })
Expand Down

0 comments on commit a4887e2

Please sign in to comment.