-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
entrypoint.ts
35 lines (29 loc) · 896 Bytes
/
entrypoint.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright 2020 the Fastro author. All rights reserved. MIT license.
import { ServerOptions } from "../core/types.ts";
import { Fastro } from "../mod.ts";
const message = `USAGE:
fastro serve [OPTIONS]
OPTIONS:
--production Disable file watching
--port [PORT] Set port of webapp
Example:
\`fastro serve --port 8080\`
`;
function serveHelp() {
return console.log(message);
}
let server: Fastro | undefined;
// deno-lint-ignore no-explicit-any
export async function serve(port?: number, args?: any) {
if (args.help) return serveHelp();
if (Deno.env.get("DENO_ENV") !== "development") {
Deno.env.set("DENO_ENV", "production");
}
try {
console.log(`DENO_ENV=${Deno.env.get("DENO_ENV")}`);
if (server) server.close();
server = new Fastro({ port });
} catch (error) {
console.error(error);
}
}