-
Notifications
You must be signed in to change notification settings - Fork 11
/
app.js
41 lines (33 loc) · 860 Bytes
/
app.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
38
39
40
41
const express = require("express");
const compression = require("compression");
const session = require("express-session");
const resolve = require("path").resolve;
const setup = require("./middlewares/frontendMiddleware");
const bodyParser = require("body-parser");
const apiRoutes = require("./api");
const port = process.env.PORT || 8080;
const app = express();
// gzip
app.use(compression());
app.use(
session({
secret: "carbon",
cookie: { maxAge: 60000 }
})
);
// body parser
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// API
app.use("/api", apiRoutes);
// static
app.use(express.static("./public"));
// front-end
setup(app, {
outputPath: resolve(process.cwd(), "public"),
publicPath: "/"
});
// start the server
app.listen(port, () => {
console.log(`live at http://localhost:${port}`);
});