forked from dagumak/lionshare-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
37 lines (31 loc) · 790 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
30
31
32
33
34
35
36
37
import Koa from "koa";
import ratelimit from "koa-ratelimit";
import compress from "koa-compress";
import logger from "koa-logger";
import mount from "koa-mount";
import cors from "./middlewares/cors";
import redis from "./db/redis";
import api from "./api";
const app = new Koa();
app.use(
ratelimit({
db: redis,
duration: 60000,
errorMessage:
"Please stop hitting us so hard. Please deploy your own instance of the API",
id: ctx => ctx.get("X-Real-IP"),
headers: {
remaining: "Rate-Limit-Remaining",
reset: "Rate-Limit-Reset",
total: "Rate-Limit-Total"
},
max: 50
})
);
app.use(compress());
app.use(cors());
app.use(mount("/api", api));
if (process.env.NODE_ENV === "development") {
app.use(logger());
}
export default app;