Skip to content

Commit

Permalink
fix(deno-server): explicitly remove cert/key from options if either i…
Browse files Browse the repository at this point in the history
…s not set (#2373)
  • Loading branch information
pi0 committed Apr 17, 2024
1 parent babe16e commit d887f4a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/presets/deno-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const denoServer = defineNitroPreset({
clearInterval: ["node:timers", "clearInterval"],
setImmediate: ["node:timers", "setImmediate"],
clearImmediate: ["node:timers", "clearImmediate"],
process: ["node:process", "default"],
// process: ["node:process", "default"],
},
},
rollupConfig: {
Expand Down
33 changes: 19 additions & 14 deletions src/runtime/entries/deno-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,26 @@ if (Deno.env.get("DEBUG")) {
);
}

// https://deno.land/api@v1.34.3?s=Deno.serve&unstable=
Deno.serve(
{
key: Deno.env.get("NITRO_SSL_KEY"),
cert: Deno.env.get("NITRO_SSL_CERT"),
port: destr(Deno.env.get("NITRO_PORT") || Deno.env.get("PORT")) || 3000,
hostname: Deno.env.get("NITRO_HOST") || Deno.env.get("HOST"),
onListen: (opts) => {
const baseURL = (useRuntimeConfig().app.baseURL || "").replace(/\/$/, "");
const url = `${opts.hostname}:${opts.port}${baseURL}`;
console.log(`Listening ${url}`);
},
// https://deno.land/api@v1.42.4?s=Deno.serve
const serveOptions = {
key: Deno.env.get("NITRO_SSL_KEY"),
cert: Deno.env.get("NITRO_SSL_CERT"),
port: destr(Deno.env.get("NITRO_PORT") || Deno.env.get("PORT")) || 3000,
hostname: Deno.env.get("NITRO_HOST") || Deno.env.get("HOST"),
onListen: (opts) => {
const baseURL = (useRuntimeConfig().app.baseURL || "").replace(/\/$/, "");
const url = `${opts.hostname}:${opts.port}${baseURL}`;
console.log(`Listening ${url}`);
},
handler
);
};

// https://github.com/unjs/nitro/pull/2373
if (!serveOptions.key || !serveOptions.cert) {
delete serveOptions.key;
delete serveOptions.cert;
}

Deno.serve(serveOptions, handler);

// Websocket support
const ws = import.meta._websocket
Expand Down

0 comments on commit d887f4a

Please sign in to comment.