-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
32 lines (25 loc) · 799 Bytes
/
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
require("dotenv").config();
const express = require("express");
const app = express();
const PORT = 3000;
const cors = require("cors");
app.use(cors({ origin: /localhost/ }));
app.use(require("morgan")("dev"));
app.use(express.json());
app.use(require("./api/auth").router);
app.use("/departments", require("./api/departments"));
// Router for professors
app.use("/professors", require("./api/professors"));
//404 middleware
app.use((req, res, next) => {
next({ status: 404, message: "Endpoint not found" });
});
//Error-handling middleware
app.use((err, req, res, next) => {
console.error(err);
res.status(err.status ?? 500);
res.json(err.message ?? "Sorry, something went wrong on the server side");
});
app.listen(PORT, () => {
console.log(`Listening on port#: ${3000}...`);
});