Fix: HTTPS + dev + API route = http://undefined/
as the request url
#821
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, if you use a self-signed cert, HTTPS, and try to use an API route on dev, the
request.url
looks likehttp://undefined/
.Example Setup
This is best exemplified in the
with-authjs
example, whose README I've updated in the first commit. Follow the instructions there, creating a.env
file, Discord app, and self-signed cert. (Apologies in advance for how long this may take.) When you click "Sign in with Discord" using that self-signed cert, it will redirect you tohttp://undefined/api/auth/signin/discord
. To demonstrate that this isn't a problem withauthjs
, go towith-authjs/src/routes/api/auth/[...solidauth].ts
and replaceexport const { GET, POST } = SolidAuth(authOptions);
withIf you revisit the login screen, you'll see the following in your console:
The Fix
The fix is implemented in the second commit. (Ignore the multiple force pushes below - I strived for a clean commit history.)
Here's a somewhat relevant section from the spec as to why the
host
header is missing; emphasis mine:Note that this only works for HTTP/2 - I don't think it'll work for HTTP/1.1. From the 1.1 spec:
I'm unsure if we can get the correct URL anywhere else in Node. See the comment below for details.
createRequest
has 3 callers,packages/start/dev/server.js
,packages/start-node/server.js
, andpackages/start-static/entry.js
, so this PR has security implications for production deployments.