-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
43 lines (37 loc) · 1.34 KB
/
app.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
require("dotenv").config();
const express = require("express");
const csurf = require("csurf");
const { join } = require("path");
const db = require("./data/database");
const rateLimiterMiddleware = require("./middlewares/rate-limiter");
const baseRoutes = require("./routes/base.routes");
const authRoutes = require("./routes/auth.routes");
const accountRoutes = require("./routes/account.routes");
const cookieParser = require("cookie-parser");
const { checkUser } = require("./middlewares/auth-middleware");
const errorHandlerMiddleware = require("./middlewares/error-handler");
const app = express();
app.set("view engine", "ejs");
app.set("views", join(__dirname, "views"));
app.use(express.static("public"));
app.use(express.static("pictures"));
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
const csrfProtection = csurf({ cookie: true, secure: true, httpOnly: true });
app.use(csrfProtection);
app.use(rateLimiterMiddleware.limiter);
app.get("*", checkUser);
app.use(baseRoutes);
app.use(authRoutes);
app.use(accountRoutes);
app.use(errorHandlerMiddleware);
db.connectToDatabase()
.then(() => {
const port = process.env.PORT || 5500;
app.listen(port, "0.0.0.0", () => {
console.log(`Server is running on port ${port}`);
});
})
.catch((error) => {
console.error("Database connection error:", error);
});