-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
46 lines (35 loc) · 1.09 KB
/
main.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
const express = require("express");
const app = express();
const morgan = require("morgan");
const helmet = require("helmet");
const rfs = require("rotating-file-stream");
const cors = require("cors");
const path = require("path");
const dotenv = require("dotenv");
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
dotenv.config();
const connectDatabase = require("./src/configs/db.config");
connectDatabase();
const port = process.env.PORT || 3333;
const isProduction = process.env.NODE_ENV === "production";
app.use(helmet());
const accessLogStream = rfs.createStream("access.log", {
interval: "1d",
path: path.join(__dirname, "log"),
});
app.use(
isProduction ? morgan("combined", { stream: accessLogStream }) : morgan("dev")
);
app.use(cors());
const routers = require('./src/routes/router')
app.use('/api', routers)
app.get("*", (req, res) => {
res.json({
message: "hello word",
});
});
app.listen(port, () => {
console.log(`Server is listening on port: ${port}`);
});