-
Notifications
You must be signed in to change notification settings - Fork 365
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: show proper req.url
in HTTPS mode
#5968
Changes from 1 commit
090d94c
58b40b3
d528543
dfa73c9
18fe0a1
3c9a98c
bb5f238
a60764c
f57689e
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { env } from 'process' | ||
|
||
const latestBootstrapURL = 'https://64c264287e9cbb0008621df3--edge.netlify.com/bootstrap/index-combined.ts' | ||
const latestBootstrapURL = 'https://deploy-preview-294--edge.netlify.app/bootstrap/index-combined.ts' | ||
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. Let's not forget to change this before merging. 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. done in bb5f238 |
||
|
||
export const getBootstrapURL = () => env.NETLIFY_EDGE_BOOTSTRAP || latestBootstrapURL |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ export const headers = { | |
DeployID: 'x-nf-deploy-id', | ||
FeatureFlags: 'x-nf-feature-flags', | ||
ForwardedHost: 'x-forwarded-host', | ||
ForwardedProtocol: 'x-forwarded-proto', | ||
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. Is this one still needed? 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. We're still using |
||
Functions: 'x-nf-edge-functions', | ||
InvocationMetadata: 'x-nf-edge-functions-metadata', | ||
Geo: 'x-nf-geo', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,8 +94,8 @@ export const initializeProxy = async ({ | |
inspectSettings, | ||
mainPort, | ||
offline, | ||
passthroughPort, | ||
projectDir, | ||
settings, | ||
siteInfo, | ||
state, | ||
}) => { | ||
|
@@ -122,6 +122,7 @@ export const initializeProxy = async ({ | |
internalFunctions, | ||
port: isolatePort, | ||
projectDir, | ||
settings, | ||
}) | ||
const hasEdgeFunctions = userFunctionsPath !== undefined || internalFunctionsPath | ||
|
||
|
@@ -167,11 +168,11 @@ export const initializeProxy = async ({ | |
} | ||
|
||
const featureFlags = ['edge_functions_bootstrap_failure_mode'] | ||
const forwardedHost = `localhost:${passthroughPort}` | ||
|
||
req[headersSymbol] = { | ||
[headers.FeatureFlags]: getFeatureFlagsHeader(featureFlags), | ||
[headers.ForwardedHost]: forwardedHost, | ||
[headers.ForwardedHost]: req.headers.host, | ||
[headers.ForwardedProtocol]: req.socket.encrypted ? 'https:' : 'http:', | ||
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. Can we make the caller method pass 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. done in dfa73c9 |
||
[headers.Functions]: functionNames.join(','), | ||
[headers.InvocationMetadata]: getInvocationMetadataHeader(invocationMetadata), | ||
[headers.IP]: LOCAL_HOST, | ||
|
@@ -182,13 +183,6 @@ export const initializeProxy = async ({ | |
req[headersSymbol][headers.DebugLogging] = '1' | ||
} | ||
|
||
// If we're using a different port for passthrough requests, which is the | ||
// case when the CLI is running on HTTPS, use it on the Host header so | ||
// that the request URL inside the edge function is something accessible. | ||
if (mainPort !== passthroughPort) { | ||
req[headersSymbol].host = forwardedHost | ||
} | ||
|
||
return `http://${LOCAL_HOST}:${isolatePort}` | ||
} | ||
} | ||
|
@@ -207,6 +201,7 @@ const prepareServer = async ({ | |
internalFunctions, | ||
port, | ||
projectDir, | ||
settings, | ||
}) => { | ||
// Merging internal with user-defined import maps. | ||
const importMapPaths = [...importMaps, config.functions['*'].deno_import_map] | ||
|
@@ -227,6 +222,7 @@ const prepareServer = async ({ | |
importMapPaths, | ||
inspectSettings, | ||
port, | ||
certificatePath: settings?.https?.certFilePath, | ||
}) | ||
const registry = new EdgeFunctionsRegistry({ | ||
bundler, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ import contentType from 'content-type' | |
import cookie from 'cookie' | ||
import { getProperty } from 'dot-prop' | ||
import generateETag from 'etag' | ||
import getAvailablePort from 'get-port' | ||
import httpProxy from 'http-proxy' | ||
import { createProxyMiddleware } from 'http-proxy-middleware' | ||
import jwtDecode from 'jwt-decode' | ||
|
@@ -681,7 +680,6 @@ export const startProxy = async function ({ | |
siteInfo, | ||
state, | ||
}) { | ||
const secondaryServerPort = settings.https ? await getAvailablePort() : null | ||
const functionsServer = settings.functionsPort ? `http://127.0.0.1:${settings.functionsPort}` : null | ||
const edgeFunctionsProxy = await initializeEdgeFunctionsProxy({ | ||
config, | ||
|
@@ -694,10 +692,10 @@ export const startProxy = async function ({ | |
inspectSettings, | ||
mainPort: settings.port, | ||
offline, | ||
passthroughPort: secondaryServerPort || settings.port, | ||
projectDir, | ||
siteInfo, | ||
accountId, | ||
settings, | ||
state, | ||
}) | ||
const proxy = await initializeProxy({ | ||
|
@@ -742,19 +740,6 @@ export const startProxy = async function ({ | |
|
||
const eventQueue = [once(primaryServer, 'listening')] | ||
|
||
// If we're running the main server on HTTPS, we need to start a secondary | ||
// server on HTTP for receiving passthrough requests from edge functions. | ||
// This lets us run the Deno server on HTTP and avoid the complications of | ||
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. With this PR, we're passing the "potentially untrusted certificate" into Deno via the This functionality was originally implemented in denoland/deno#3972, and it works by adding the cert as a trusted root certificate to the HTTP client: From my perspective, this should be fine. Maybe Eduardo can elaborate on the complications they had in mind when they're back. 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. Have you seen the PR that introduced that functionality? #5409 |
||
// Deno talking to Node on HTTPS with potentially untrusted certificates. | ||
if (secondaryServerPort) { | ||
const secondaryServer = http.createServer(onRequestWithOptions) | ||
|
||
secondaryServer.on('upgrade', onUpgrade) | ||
secondaryServer.listen({ port: secondaryServerPort }) | ||
|
||
eventQueue.push(once(secondaryServer, 'listening')) | ||
} | ||
|
||
await Promise.all(eventQueue) | ||
|
||
return getProxyUrl(settings) | ||
|
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 need to merge the ef-bootstrap PR first, so we can update the URL here.