-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
39 lines (30 loc) · 932 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
const express = require("express");
const pino = require("pino");
require("dotenv").config();
const bodyParser = require("body-parser");
const router = require("./routes/index");
const PORT = process.env.PORT || 3000;
const logger = pino();
const app = express();
app.use(require("cors")());
app.use(require("cookie-parser")());
app.use(require("compression")());
app.use(
require("helmet")({
contentSecurityPolicy: false,
crossOriginEmbedderPolicy: false,
crossOriginResourcePolicy: false,
crossOriginOpenerPolicy: false,
}),
);
app.use((req, res, next) => {
req.time = new Date(Date.now()).toString();
logger.info(req.method, req.hostname, req.path, req.time);
next();
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.use(router);
app.listen(PORT, () => {
console.log(`App is running on http://localhost:${PORT}`);
});