-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
63 lines (51 loc) · 1.57 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const express = require("express");
const path = require("path");
const config = require("dotenv");
const cors = require("cors");
const compression = require("compression");
const colors = require("colors");
const app = express();
const morgan = require("morgan");
const halmet = require("helmet");
// custom module import
const connectDB = require("./config/db");
const error = require("./middleware/error.middleware");
app.use(compression());
app.use(express.json());
app.use(
halmet({
contentSecurityPolicy: true,
frameguard: true,
})
);
//Load envirnoment variable
config.config({ path: "./.env" });
// Dev logging middleware
if (process.env.NODE_ENV === "development") {
app.use(morgan("dev"));
}
// enable cors
app.use(cors());
// Ping app for testing connection
app.get("/ping", (req, res) => res.status(200).send("Hello world!"));
// Mount routers
require("./app/media/routesDefinations/media.routesDefs")(app);
require("./app/programs/routesDefinations/programs.routeDefs")(app);
require("./app/extras/routesDefinations/extras.routeDefs")(app);
require("./app/product/routesDefinations/product.routeDefs")(app);
// Set static folder
app.use('/public', express.static('public'));
// Connect to database
connectDB();
app.use(error);
const port = process.env.PORT || 7000;
const server = app.listen(port, () => {
console.log(
`Server running in ${process.env.NODE_ENV} mode on port http://localhost:${port}`
.yellow
);
});
// Handle unhandled promise rejections
process.on("unhandledRejection", (err, promise) => {
console.log(`Error: ${err.message}`.red);
});