-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathcli.ts
57 lines (47 loc) · 1.41 KB
/
cli.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import "./env";
import path from "node:path";
import os from "node:os";
import { broadcastDevReady, installGlobals } from "@remix-run/node";
import sourceMapSupport from "source-map-support";
import { createApp } from "./index";
sourceMapSupport.install();
installGlobals();
let port = process.env.PORT ? Number(process.env.PORT) : 3000;
if (Number.isNaN(port)) port = 3000;
let buildPathArg = process.argv[2];
if (!buildPathArg) {
console.error(`
Usage: remix-serve <build-dir>`);
process.exit(1);
}
let buildPath = path.resolve(process.cwd(), buildPathArg);
let build = require(buildPath);
let onListen = () => {
let address =
process.env.HOST ||
Object.values(os.networkInterfaces())
.flat()
.find((ip) => String(ip?.family).includes("4") && !ip?.internal)?.address;
if (!address) {
console.log(`Remix App Server started at http://localhost:${port}`);
} else {
console.log(
`Remix App Server started at http://localhost:${port} (http://${address}:${port})`
);
}
if (process.env.NODE_ENV === "development") {
broadcastDevReady(build);
}
};
let app = createApp(
buildPath,
process.env.NODE_ENV,
build.publicPath,
build.assetsBuildDirectory
);
let server = process.env.HOST
? app.listen(port, process.env.HOST, onListen)
: app.listen(port, onListen);
["SIGTERM", "SIGINT"].forEach((signal) => {
process.once(signal, () => server?.close(console.error));
});