-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
89 lines (73 loc) · 1.85 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
82
83
84
85
86
87
88
89
//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";
// API DOcumenATion
import swaggerUi from "swagger-ui-express";
import swaggerDoc from "swagger-jsdoc";
//securty packages
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 authRoutes from "./routes/authRoutes.js";
import errorMiddleware from "./middlewares/errorMiddleware.js";
import userRoutes from "./routes/userRoutes.js";
import jobsRoutes from "./routes/jobsRoute.js";
//Dot ENV config
dotenv.config();
//mongodb connection
connectDB();
//rest object
const app = express();
// Swagger api config
// swagger api options
const options = {
definition: {
openapi: "3.0.0",
info: {
title: "Job Application",
description: "Node Expressjs Job Application",
},
servers: [
{
// url: "http://localhost:4000",
url: "https://nodejs-t7ka.onrender.com"
},
],
},
apis: ["./routes/*.js"],
};
const spec = swaggerDoc(options);
//middelwares
app.use(helmet(``));
app.use(xss());
app.use(mongoSanitize());
app.use(express.json());
app.use(cors());
app.use(morgan("dev"));
//routes
app.get("/", (req, res) => {
res.send("Server is running...");
});
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 middleware
app.use(errorMiddleware);
//port
const PORT = process.env.PORT || 4000;
//listen
app.listen(PORT, () => {
console.log(
`Node Server Running In ${process.env.NODE_ENV} Mode on port no ${PORT}`
.bgCyan.white
);
});