Skip to content

Commit

Permalink
refactor: always rely on getFunctionForURLPath
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt committed Oct 9, 2023
1 parent cb03449 commit 6dd8aec
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/utils/proxy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -329,24 +329,24 @@ const serveRedirect = async function ({ env, functionsRegistry, match, options,
return proxy.web(req, res, { target: options.functionsServer })
}

const functionWithCustomRoute =
functionsRegistry && (await functionsRegistry.getFunctionForURLPath(destURL, req.method))
const matchingFunction = functionsRegistry && (await functionsRegistry.getFunctionForURLPath(destURL, req.method))
const destStaticFile = await getStatic(dest.pathname, options.publicFolder)
let statusValue
if (
match.force ||
(!staticFile && ((!options.framework && destStaticFile) || isInternal(destURL) || functionWithCustomRoute))
(!staticFile && ((!options.framework && destStaticFile) || isInternal(destURL) || matchingFunction))
) {
req.url = destStaticFile ? destStaticFile + dest.search : destURL
const { status } = match
statusValue = status
console.log(`${NETLIFYDEVLOG} Rewrote URL to`, req.url)
}

if (isFunction(options.functionsPort, req.url) || functionWithCustomRoute) {
const functionHeaders = functionWithCustomRoute
? { [NFFunctionName]: functionWithCustomRoute.func.name, [NFFunctionRoute]: functionWithCustomRoute.route }
: {}
if (matchingFunction) {
const functionHeaders = {
[NFFunctionName]: matchingFunction.func.name,
[NFFunctionRoute]: matchingFunction.route,
}
const url = reqToURL(req, originalURL)
req.headers['x-netlify-original-pathname'] = url.pathname
req.headers['x-netlify-original-search'] = url.search
Expand Down

0 comments on commit 6dd8aec

Please sign in to comment.