Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't run form submission logic on paths matching function #6048

Merged
merged 5 commits into from
Oct 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' || (await functionsRegistry.getFunctionForURLPath(req.url, req.method))) return next()
if (
req.url.startsWith('/.netlify/') ||
req.method !== 'POST' ||
(await functionsRegistry.getFunctionForURLPath(req.url, req.method))
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible that functionsRegistry isn't defined here? It's a bit hard to tell, but we do have a few checks for it elsewhere in the codebase, which makes me think it may not be there at times.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what i'm seeing, this is the only codepath where this is ever going to be called:

const functionsRegistry = new FunctionsRegistry({
capabilities,
config,
debug,
isConnected: Boolean(siteUrl),
// functions always need to be inside the packagePath if set inside a monorepo
projectRoot: command.workingDir,
settings,
timeouts,
})
await functionsRegistry.scan(functionsDirectories)
const server = getFunctionsServer(Object.assign(options, { functionsRegistry }))

So functionsRegistry is always defined.

Copy link
Member

Choose a reason for hiding this comment

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

👍🏻 🚀

)
return next()

const fakeRequest = new Readable({
read() {
Expand Down