-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
67 lines (53 loc) · 1.88 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
58
59
60
61
62
63
64
65
66
67
// Node Requirements
const path = require("path");
// Inner Requirements
const connectDB = require("./config/db");
const winston = require("./config/winston");
const { errorHandler } = require("./middlewares/errors");
const { setHeaders } = require("./middlewares/headers");
const { limiter } = require("./config/rateLimit");
// Outer Requirements
const fileUpload = require("express-fileupload");
const express = require("express");
const dotEnv = require("dotenv");
const morgan = require("morgan");
// Load Config
dotEnv.config({ path: "./config/config.env" });
// ENVs
const PORT = process.env.PORT || 3000;
const NODE_ENV = process.env.NODE_ENV;
// Database Connection
connectDB();
// App
const app = express();
// Rate Limiter
app.use(limiter);
// Logging
if (process.env.NODE_ENV === "development")
app.use(morgan("combined", { stream: winston.stream }));
// BodyParser
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(setHeaders);
// File Upload
app.use(fileUpload());
// Static Folder
app.use(express.static(path.join(__dirname, "public")));
// Routes
app.use("/", require("./routes/userRouter"));
app.use("/admin/roles", require("./routes/roleManagementRouter"));
app.use("/admin/users", require("./routes/userManagementRouter"));
app.use("/admin/categories", require("./routes/categoryRouter"));
app.use("/comments", require("./routes/commentRouter"));
app.use("/p", require("./routes/blogRouter"));
app.use("/admin/blogs", require("./routes/blogManagementRouter"));
app.use("/admin/tags", require("./routes/tagRouter"));
app.use("/admin/url-roles", require("./routes/urlRolesRouter"));
app.use("/news-scrapper", require("./routes/newsScrapperRouter"));
// Error Controller
app.use(errorHandler);
// Port Settings
app.listen(PORT, () => {
console.log("***********************");
console.log(`Server started on ${PORT} && running on ${NODE_ENV} mode`);
});