-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
50 lines (43 loc) · 1.22 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
require("dotenv").config();
const mongoose = require("mongoose");
const cors = require("cors");
const winston = require("winston");
const helmet = require("helmet");
const express = require("express");
const ReminderRoutes = require("./routes/ReminderRoutes");
const UserRoutes = require("./routes/UserRoutes");
const FilterRoutes = require("./routes/FilterRoutes");
const LabelRoutes = require("./routes/LabelRoutes");
const ProjectRoutes = require("./routes/ProjectRoutes");
const app = express();
app.use(cors());
// middleware
app.use(express.json());
// prevent XSS attacks
app.use(helmet());
app.use((req, res, next) => {
winston.log("info", "Request received");
next();
});
// routes
app.use("/reminder", ReminderRoutes);
app.use("/user", UserRoutes);
app.use("/filter", FilterRoutes);
app.use("/label", LabelRoutes);
app.use("/project", ProjectRoutes);
const PORT = process.env.PORT || 3000;
// connect to db with mongoose
mongoose
.connect(process.env.DB_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
winston.log("info", "Connected to DB");
})
.catch((err) => {
winston.error(err);
});
app.listen(PORT, () => {
winston.log("info", `Server is running on port ${PORT}`);
});