Skip to content

Commit

Permalink
fix: detect https protocol in development
Browse files Browse the repository at this point in the history
We use https for development at Webstudio.
While setup we found somes requests always have "http" protocl.
Turns out origin is not sent with get requests and node-adapter
falls back into "http".

Here added https detection based on express internals.
  • Loading branch information
TrySound committed Nov 7, 2024
1 parent 9f06bfb commit 104636b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/remix-dev/vite/node-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { IncomingHttpHeaders, ServerResponse } from "node:http";
import { TLSSocket } from "node:tls";
import { once } from "node:events";
import { Readable } from "node:stream";
import { splitCookiesString } from "set-cookie-parser";
Expand Down Expand Up @@ -35,10 +36,14 @@ export function fromNodeRequest(
nodeReq: Vite.Connect.IncomingMessage,
nodeRes: ServerResponse<Vite.Connect.IncomingMessage>
): Request {
const protocol =
nodeReq.socket instanceof TLSSocket && nodeReq.socket.encrypted
? "https"
: "http";
let origin =
nodeReq.headers.origin && "null" !== nodeReq.headers.origin
? nodeReq.headers.origin
: `http://${nodeReq.headers.host}`;
: `${protocol}://${nodeReq.headers.host}`;
// Use `req.originalUrl` so Remix is aware of the full path
invariant(
nodeReq.originalUrl,
Expand Down

0 comments on commit 104636b

Please sign in to comment.