-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (33 loc) · 1.19 KB
/
index.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
40
import bodyParser from 'body-parser';
import cors from 'cors';
import express from 'express';
import rateLimit from 'express-rate-limit';
// import helmet from 'helmet';
import config from './config/config.js';
import routes from './src/routes/index.js';
const app = express();
const PORT = config.port ?? 3000;
const HOST = config.host ?? 'localhost';
//** middleware **/
app.use(cors()); // enables Cross-Origin Resource Sharing
// app.use(helmet({ crossOriginResourcePolicy: false })); // adds various HTTP headers to secure the app
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(express.static('uploads'));
// rate limiting middleware
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit each IP to 100 requests per windowMs
message: 'Too many requests from this IP, please try again later',
});
app.use(limiter); // apply rate limiting to all routes under '/'
app.use(routes);
app.get('/', (_req, res) => {
res.json({
message: 'Eary-System web app 💻✌',
github: 'https://github.com/Adosh74/Eary-System',
});
});
app.listen(PORT, '0.0.0.0', () => {
console.log(`Serving running on http://${HOST}:${PORT}`);
});