-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
29 lines (29 loc) · 995 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
27
28
29
// Import the dotenv module and call the config() method
const dotenv = require("dotenv").config();
// Import the express module
const express = require("express");
// Import the sanitizer module
const sanitize = require('sanitize');
// Import the cors module
const cors = require("cors");
// Set up the CORS options to allow requests from our front-end
const corsOptions = {
origin: process.env.FRONTEND_URL,
optionsSuccessStatus: 200
};
// Create an instance of express
const app = express();
// Use the express.json() middleware to parse the request body
app.use(express.json());
// Add the sanitizer to the express middleware
app.use(sanitize.middleware);
// Allow CORS to all
app.use(cors());
// Import the routes
const routes = require('./routes');
// Add the routes to the middleware chain
app.use(routes);
// Get the port from the environment variable
const port = process.env.PORT;
// Set up the listener
app.listen(port, () => console.log(`Listening on port ${port}`));