-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (47 loc) · 1.33 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const express = require("express");
const cors = require("cors");
const createError = require("http-errors");
const logger = require("morgan");
require("dotenv").config();
const compression = require("compression");
const helmet = require("helmet");
const RateLimit = require("express-rate-limit");
const postRouter = require("./routes/postRouter");
const userRouter = require("./routes/userRouter");
const commentRouter = require("./routes/commentRouter");
const port = process.env.PORT;
const limiter = RateLimit({
windowMs: 1 * 60 * 1000,
max: 100,
});
const app = express();
app.use(compression());
app.use(helmet());
app.use(limiter);
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(
cors({
origin: [
"https://almagorge-admin-portal.netlify.app",
"https://almagorge.netlify.app",
"http://localhost:5173",
],
})
);
app.use("/users", userRouter);
app.use("/posts", postRouter);
app.use("/comments", commentRouter);
app.use((req, res, next) => {
next(createError(404));
});
app.use((err, req, res, next) => {
res.locals.message = err.message;
res.locals.error = req.app.get("env") === "development" ? err : {};
res.status(err.status || 500);
res.render("error");
});
app.listen(port, () => {
console.log(`Currently running on port ${port}`);
});