summaryrefslogtreecommitdiff
path: root/server/src/API/API.ts
blob: 8a6eb0f93810aa65cc9aad92aab43d377e553469 (plain) (blame)
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
import { AkairoClient } from 'discord-akairo';
import express, { Application } from 'express';
import { createServer } from 'http';
import cors from 'cors';
import OAuth2 from '../structures/OAuth2';

import OAuth2Router from './routers/OAuth2Router';
import GuildRouter from './routers/GuildRouter';

export default class API {
    protected client: AkairoClient;
    protected server: Application;
    protected oauth: OAuth2;
    
    public constructor(client: AkairoClient) {
        this.client = client;
        this.oauth = new OAuth2(this.client);
    }
    
    public start(): void {
        this.server = express();
        this.server.use(express.json());
        this.server.use(cors({
            origin: true,
            credentials: true
        }));
        
        new OAuth2Router(this.server, this.client, this.oauth);
        new GuildRouter(this.server, this.client);
        
        createServer(this.server).listen(8088, (): void => console.log('API is online.'));
    }
}