Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions packages/cli/src/tempserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export async function spawnTemporaryServer(
const server = serve({
port: serverPort,
hostname: "::",
fetch: fetch,
silent: true,
fetch,
});
await server.ready();
const url = new URL(server.url!);
Expand All @@ -41,30 +42,36 @@ export async function spawnTemporaryServer(
}

const server = serve({
fetch: (request) => {
const url = new URL(request.url);
url.protocol = "https:";
request = new Request(url, {
method: request.method,
headers: request.headers,
body: request.method === "GET" || request.method === "HEAD"
? null
: request.body,
referrer: request.referrer,
referrerPolicy: request.referrerPolicy,
mode: request.mode,
credentials: request.credentials,
cache: request.cache,
redirect: request.redirect,
integrity: request.integrity,
keepalive: request.keepalive,
signal: request.signal,
});
// Note that `protocol: "https"` does not work on Deno, so we need to
// manually rewrite the request URL to use https: on Deno:
fetch: "Deno" in globalThis
Comment thread
dahlia marked this conversation as resolved.
? (request) => {
const url = new URL(request.url);
url.protocol = "https:";
const newRequest = new Request(url, {
method: request.method,
headers: request.headers,
body: request.method === "GET" || request.method === "HEAD"
? null
: request.body,
referrer: request.referrer,
referrerPolicy: request.referrerPolicy,
mode: request.mode,
credentials: request.credentials,
cache: request.cache,
redirect: request.redirect,
integrity: request.integrity,
keepalive: request.keepalive,
signal: request.signal,
});

return new Response();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the cause.

},
return fetch(newRequest);
}
: fetch,
port: serverPort,
hostname: "::",
silent: true,
protocol: "https",
});

await server.ready();
Expand All @@ -74,10 +81,7 @@ export async function spawnTemporaryServer(

logger.debug("Temporary server is listening on port {port}.", { port });
const tun = await openTunnel({ port: parseInt(port) });
logger.debug(
"Temporary server is tunneled to {url}.",
{ url: tun.url.href },
);
logger.debug("Temporary server is tunneled to {url}.", { url: tun.url.href });

return {
url: tun.url,
Expand Down
Loading