-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathserver.mjs
40 lines (34 loc) · 885 Bytes
/
server.mjs
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
import {
unstable_createViteServer,
unstable_loadViteServerBuild,
} from "@remix-run/dev";
import { createRequestHandler } from "@remix-run/express";
import { installGlobals } from "@remix-run/node";
import express from "express";
installGlobals();
let vite =
process.env.NODE_ENV === "production"
? undefined
: await unstable_createViteServer();
const app = express();
// handle asset requests
if (vite) {
app.use(vite.middlewares);
} else {
app.use(
"/build",
express.static("public/build", { immutable: true, maxAge: "1y" }),
);
}
app.use(express.static("public", { maxAge: "1h" }));
// handle SSR requests
app.all(
"*",
createRequestHandler({
build: vite
? () => unstable_loadViteServerBuild(vite)
: await import("./build/index.js"),
}),
);
const port = 3000;
app.listen(port, () => console.log("http://localhost:" + port));