forked from jimmylee/next-express-emotion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
37 lines (30 loc) · 822 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
36
37
import express from "express";
import next from "next";
import BodyParser from "body-parser";
import compression from "compression";
const dev = process.env.NODE_ENV !== "production";
const port = process.env.PORT || 8080;
const app = next({ dev, quiet: false });
const nextRequestHandler = app.getRequestHandler();
app.prepare().then(() => {
const server = express();
if (!dev) {
server.use(compression());
}
server.use("/public", express.static("public"));
server.use(BodyParser.json());
server.use(
BodyParser.urlencoded({
extended: false,
})
);
server.get("*", async (req, res) => {
return nextRequestHandler(req, res, req.url);
});
server.listen(port, (err) => {
if (err) {
throw err;
}
console.log(`[ server ]: http://localhost:${port}`);
});
});