-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
39 lines (32 loc) · 1.06 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
/* modules */
const express = require('express');
const RateLimit = require('express-rate-limit');
/* imports and variables */
const Global = require('./global.js');
const Pokemon = require('./pokemon.js');
const apiLimiter = RateLimit({
windowMs: 5 * 60 * 1000, // 5 minutes
max: 150, // limit each IP to 100 requests per windowMs
delayMs: 0, // disable delaying - full speed until the max limit is reached
});
const app = express();
/* middleware */
app.disable('x-powered-by');
app.use('*', apiLimiter);
/* set view engine */
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
/* static files */
app.use(express.static('public'));
app.use('/css', express.static(__dirname + 'public/css'));
app.use('/js', express.static(__dirname + 'public/js'));
app.use('/imgs', express.static(__dirname + 'public/imgs'));
app.get('/', (req, res) => {
res.render('index');
});
app.get('/api/pokemon', (req, res) => {
return res.status(200).json(Pokemon);
});
app.listen(Global.port, () => {
console.log(`Server is running on port ${Global.port}`);
});