feat: use PORT environment variable to change port (#468)

This can be useful when deploying to other providers.

Also more convenient for projects with multiple developers with port
preferences

---------

Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
Savin Angel-Mario
2023-06-05 09:08:46 +02:00
committed by GitHub
co-authored by Asher Gomez
parent 65e6385bc4
commit 6e1874ccca
3 changed files with 51 additions and 1 deletions
+2 -1
View File
@@ -67,9 +67,10 @@ export async function createHandler(
const ctx = await ServerContext.fromManifest(routes, opts);
return ctx.handler();
}
export async function start(routes: Manifest, opts: StartOptions = {}) {
const ctx = await ServerContext.fromManifest(routes, opts);
opts.port ??= 8000;
opts.port ??= parseInt(Deno.env.get("PORT") || "8000");
if (opts.experimentalDenoServe === true) {
// @ts-ignore as `Deno.serve` is still unstable.
await Deno.serve(ctx.handler() as Deno.ServeHandler, opts);