forked from remix-run/starter-express
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
35 lines (28 loc) · 1009 Bytes
/
server.js
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
const express = require("express");
const compression = require("compression");
const morgan = require("morgan");
const { createRequestHandler } = require("@remix-run/express");
let app = express();
// Responses should be served with compression to minimize total network bytes.
// However, where this compression happens can vary wildly depending on your stack
// and infrastructure. Here we are compressing all our Express responses for the
// purpose of this starter repository, but feel free to (re)move it or change it.
app.use(compression());
app.use(express.static("public"));
if (process.env.NODE_ENV === "development") {
app.use(morgan("dev"));
}
app.all(
"*",
createRequestHandler({
build: require("./build"),
getLoadContext() {
// Whatever you return here will be passed as `context` to your loaders
// and actions.
}
})
);
let port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Express server started on http://localhost:${port}`);
});