-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
26 lines (24 loc) · 948 Bytes
/
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
require("dotenv").config();
const express = require("express");
const app = express();
const port = process.env.PORT || 3000;
const connectDB = require("./db/connect");
const errorHanlder = require("./middlewares/error-handler");
const endpointNotFound = require("./middlewares/endpointNotFound");
const authenticationRouter = require("./routes/authentication");
const authorizationMiddleware = require("./middlewares/authorization");
const httpStatusText = require("./utils/httpStatusText");
connectDB(process.env.MONGO_URI, () => {
app.listen(port, () => console.log(`Server listening on port ${port}....`));
});
app.use(express.json());
app.use("/api/v1/auth", authenticationRouter);
app.use(endpointNotFound);
app.use(authorizationMiddleware);
// authorization test
app.get("/protectedRoute", async (req, res) => {
res
.status(200)
.json({ status: httpStatusText.SUCCESS, data: { userID: req.user } });
});
app.use(errorHanlder);