-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (29 loc) · 894 Bytes
/
index.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 morgan = require("morgan");
const helmet = require("helmet");
const compression = require("compression");
const dotenv = require("dotenv");
dotenv.config();
const app = express();
const PORT = process.env.PORT || 5000;
const hostname = process.env.HOSTNAME || "localhost";
const router = require("./api/routes/routes");
if (process.env.NODE_ENV === "production") {
app.use(
morgan("common", {
skip: (req, res) => res.statusCode < 400,
stream: `${__dirname}/../morgan.log`,
})
);
} else {
app.use(morgan("dev"));
}
app.use("/api/muvis", router);
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(compression());
app.use(helmet());
app.use((err, req, res, next) => {
res.json({ message: err.message });
});
app.listen(PORT, () => console.log(`Server listening on ${hostname}:${PORT}`));