-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathindex.js
More file actions
46 lines (37 loc) · 1.01 KB
/
index.js
File metadata and controls
46 lines (37 loc) · 1.01 KB
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 morgan = require("morgan");
const helmet = require("helmet");
const rfs = require("rotating-file-stream");
import path from "path";
const cors = require("cors");
const dotenv = require("dotenv");
import connectDatabase from "./src/configs/db.config";
dotenv.config();
connectDatabase();
const port = process.env.PORT || 3333;
const isProduction = process.env.NODE_ENV === "production";
const app = express();
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());
app.use(express.json());
app.use("/api", require("./src/routes/router").default);
app.get("/", (req, res) => {
res.json({
message: "Hello Ong Dev",
});
});
app.get("*", (req, res) => {
res.json({
message: "Hello Ong Dev",
});
});
app.listen(port, () => {
console.log(`Server is listening on port: ${port}`);
});