-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathserver.js
81 lines (71 loc) · 1.82 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// API DOcumenATion
import swaggerUi from "swagger-ui-express";
import swaggerDoc from "swagger-jsdoc";
// packages imports
import express from "express";
import "express-async-errors";
import dotenv from "dotenv";
import colors from "colors";
import cors from "cors";
import morgan from "morgan";
//securty packges
import helmet from "helmet";
import xss from "xss-clean";
import mongoSanitize from "express-mongo-sanitize";
// files imports
import connectDB from "./config/db.js";
// routes import
import testRoutes from "./routes/testRoutes.js";
import authRoutes from "./routes/authRoutes.js";
import errroMiddelware from "./middelwares/errroMiddleware.js";
import jobsRoutes from "./routes/jobsRoute.js";
import userRoutes from "./routes/userRoutes.js";
//Dot ENV config
dotenv.config();
// mongodb connection
connectDB();
// Swagger api config
// swagger api options
const options = {
definition: {
openapi: "3.0.0",
info: {
title: "Job Portal Application",
description: "Node Expressjs Job Portal Application",
},
servers: [
{
url: "http://localhost:8080",
},
],
},
apis: ["./routes/*.js"],
};
const spec = swaggerDoc(options);
//rest object
const app = express();
//middelwares
app.use(helmet(``));
app.use(xss());
app.use(mongoSanitize());
app.use(express.json());
app.use(cors());
app.use(morgan("dev"));
//routes
app.use("/api/v1/test", testRoutes);
app.use("/api/v1/auth", authRoutes);
app.use("/api/v1/user", userRoutes);
app.use("/api/v1/job", jobsRoutes);
//homeroute root
app.use("/api-doc", swaggerUi.serve, swaggerUi.setup(spec));
//validation middelware
app.use(errroMiddelware);
//port
const PORT = process.env.PORT || 8080;
//listen
app.listen(PORT, () => {
console.log(
`Node Server Running In ${process.env.DEV_MODE} Mode on port no ${PORT}`
.bgCyan.white
);
});