1 |
import DiscordClient from "../client/Client"; |
import DiscordClient from "../client/Client"; |
2 |
import Service from "../utils/structures/Service"; |
import Service from "../utils/structures/Service"; |
3 |
import express, { Express } from 'express'; |
import express, { Express, Router as ExpressRouter } from 'express'; |
4 |
import Router from "./Router"; |
import Router from "./Router"; |
5 |
import path from "path"; |
import path from "path"; |
6 |
|
import rateLimit from 'express-rate-limit'; |
7 |
|
|
8 |
export interface ServerOptions { |
export interface ServerOptions { |
9 |
port?: number; |
port?: number; |
22 |
} |
} |
23 |
|
|
24 |
async boot() { |
async boot() { |
25 |
|
type methods = 'get' | 'post' | 'put' | 'patch' | 'delete'; |
26 |
|
const expressRouter = ExpressRouter(); |
27 |
|
|
28 |
|
expressRouter.use(rateLimit({ |
29 |
|
windowMs: 1 * 60 * 1000, |
30 |
|
max: 50, |
31 |
|
standardHeaders: true, |
32 |
|
legacyHeaders: true, |
33 |
|
message: { code: 429, error: 'Too many requests at a time. Please try again later.' }, |
34 |
|
})); |
35 |
|
|
36 |
await this.router.loadRoutes(); |
await this.router.loadRoutes(); |
37 |
|
|
38 |
|
for (const route of this.router.routes) { |
39 |
|
expressRouter[route.method.toLowerCase() as methods](route.path, ...route.middlewareList, await route.getCallbackFunction()); |
40 |
|
} |
41 |
|
|
42 |
|
this.express.use(expressRouter); |
43 |
} |
} |
44 |
|
|
45 |
async run() { |
async run() { |