-
Notifications
You must be signed in to change notification settings - Fork 352
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
feat: return 404 on default URL when function has custom routes #5998
Changes from all commits
933fcbb
c46ce67
556d545
67c7aeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -14,6 +14,7 @@ import { getPathInProject } from '../settings.mjs' | |||||||||||||||||||||||
import NetlifyFunction from './netlify-function.mjs' | ||||||||||||||||||||||||
import runtimes from './runtimes/index.mjs' | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
const DEFAULT_URL_EXPRESSION = /^\/.netlify\/(functions|builders)\/([^/]+).*/ | ||||||||||||||||||||||||
const ZIP_EXTENSION = '.zip' | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
export class FunctionsRegistry { | ||||||||||||||||||||||||
|
@@ -123,6 +124,32 @@ export class FunctionsRegistry { | |||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
async getFunctionForURLPath(urlPath, method) { | ||||||||||||||||||||||||
const defaultURLMatch = urlPath.match(DEFAULT_URL_EXPRESSION) | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this block should live in It'd probably result in more regex matchings needed to be done, but I don't think that's a performance concern at the orders of magnitude that functions have in local dev. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, scratch that - would make cli/src/lib/functions/registry.mjs Lines 137 to 147 in 05c44a6
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
if (defaultURLMatch) { | ||||||||||||||||||||||||
const func = this.get(defaultURLMatch[2]) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if (!func) { | ||||||||||||||||||||||||
return | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
const { routes = [] } = await func.getBuildData() | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if (routes.length !== 0) { | ||||||||||||||||||||||||
const paths = routes.map((route) => chalk.underline(route.pattern)).join(', ') | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
warn( | ||||||||||||||||||||||||
`Function ${chalk.yellow(func.name)} cannot be invoked on ${chalk.underline( | ||||||||||||||||||||||||
urlPath, | ||||||||||||||||||||||||
)}, because the function has the following URL paths defined: ${paths}`, | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
return | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
return { func, route: null } | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
for (const func of this.functions.values()) { | ||||||||||||||||||||||||
const route = await func.matchURLPath(urlPath, method) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be refactoring this so that the regex is shared with
isFunction
cli/src/utils/proxy.mjs
Lines 85 to 91 in 556d545