-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
30 lines (22 loc) · 1.05 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
/* Imports for the server */
const express = require("express"); // Import needed for setting up the Express server itself
const cors = require("cors"); // Set up CORS policy - allows interaction with client app
const helmet = require("helmet"); // For security
const morgan = require("morgan"); // For logging
// Importing routers
const rootRouter = require("./middleware/routes/root/router.js"); // Router for root URL of application ("/" route)
const UsersRouter = require("./middleware/routes/Users/router.js"); // For handling app users
const errorRouter = require("./middleware/routes/error/router.js"); // Router for handling bad requests
// Setting up the express server
const server = express();
// Built-in middleware to be able to work with JSON files
server.use(express.json());
// Applying third party middleware
server.use(cors());
server.use(helmet());
server.use(morgan("dev")); // Log setting for developer use
// Adding routers
server.use("/", rootRouter);
server.use("/api/users", UsersRouter);
server.use(errorRouter);
module.exports = server;