-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
43 lines (31 loc) · 1.25 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
40
41
42
43
const feathers = require('@feathersjs/feathers');
const express = require('@feathersjs/express');
const cors = require('cors');
const expressRateLimit = require('express-rate-limit');
const config = require('./config');
const ChampionMasteriesService = require('./services/champion-masteries/champion-masteries.service');
const app = express(feathers());
const corsOptions = {
origin: (origin, callback) => {
if (origin !== config.lolotOrigin) {
return callback(new Error('CORS policy violation'), false);
}
return callback(null, true)
},
optionsSuccessStatus: 200
};
const port = process.env.PORT || 8080;
app.use(cors(corsOptions));
// Turn on JSON body parsing for REST services
app.use(express.json())
// Turn on URL-encoded body parsing for REST services
app.use(express.urlencoded({ extended: true }));
// Set up REST transport using Express
app.configure(express.rest());
// Set up rate limiter to adhere to the rate limits of the Riot Games API key
const rateLimiter = expressRateLimit({
windowMs: 2 * 60 * 1000, // 2 minutes
max: 100 // 100 requests
});
app.use('api/champion-masteries', rateLimiter, new ChampionMasteriesService());
app.listen(port, () => console.log(`LOLOT REST API listening on http://localhost:${port}`));