-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (37 loc) · 1.46 KB
/
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
30
31
32
33
34
35
36
37
38
39
// Requirements / Imports
const express = require('express'); // express library
const bodyParser = require('body-parser'); // Node.js body parsing middleware.
const rateLimit = require("express-rate-limit"); //rate limiting
const helmet = require('helmet'); // Set secure HTTP Headers
const morgan = require('morgan'); // Extended Logging
// Start of the actual App
const app = express();
// Add Middleware
const limiter = rateLimit({
windowMs: 60 * 60 * 1000, // 1 hour
max: 10 // limit each IP to x requests per windowMs
});
const swaggerUi = require('swagger-ui-express'); // swagger ui package
const YAML = require('yamljs'); // yaml parser for swagger file
const swaggerDocument = YAML.load('./swagger.yaml'); // load swagger file
// apply to all requests
app.use(limiter);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(morgan("combined"));
app.use(helmet());
app.use(helmet.xssFilter());
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); // show swagger ui
//Add authorization middleware
let authorization=require('./src/authorization');
app.use(authorization.isAuthorised)
app.use(authorization.needsAdminRights)
// Add error handling middleware
let error_handling=require('./src/error_handling');
app.use(error_handling)
// Initialize all routes:
require("./src/routes")(app);
const port = 3000 // start the server on this port
app.listen(port, () => {
console.log(`Server is running on port ${port}!`);
});