/[sudobot]/trunk/src/api/Server.ts
ViewVC logotype

Annotation of /trunk/src/api/Server.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 323 - (hide annotations)
Mon Jul 29 17:29:32 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 882 byte(s)
feat: add basic server and routing
1 rakin 323 import DiscordClient from "../client/Client";
2     import Service from "../utils/structures/Service";
3     import express, { Express } from 'express';
4     import Router from "./Router";
5     import path from "path";
6    
7     export interface ServerOptions {
8     port?: number;
9     }
10    
11     export default class Server extends Service {
12     port: number;
13     express: Express;
14     router: Router;
15    
16     constructor(client: DiscordClient, { port = 4000 }: ServerOptions = {}) {
17     super(client);
18     this.port = port;
19     this.express = express();
20     this.router = new Router(client, this, { routesDir: path.resolve(__dirname, 'routes') });
21     }
22    
23     async boot() {
24     await this.router.loadRoutes();
25     }
26    
27     async run() {
28     await this.boot();
29    
30     this.express.listen(this.port, () => {
31     console.log(`API Server listening at port ${this.port}`);
32     });
33     }
34     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26