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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 53 - (hide annotations)
Mon Jul 29 17:28:23 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 1333 byte(s)
Push api directory
1 rakin 53 import DiscordClient from "../client/Client";
2     import express, { Application, Request, Response } from 'express';
3     import routes from './routes';
4     import router from "./Router";
5     import { readFileSync } from "fs";
6     import path from "path";
7    
8     export default class Server {
9     app: Application;
10     port: number = 4000;
11     guildData: {
12     [key: string]: {
13     token: string;
14     }
15     };
16    
17     constructor(protected client: DiscordClient) {
18     this.app = express();
19     this.guildData = JSON.parse(readFileSync(path.resolve(__dirname, '..', '..', 'config', 'apiguilds.json')).toString());
20     }
21    
22     verifyToken(guild: string, token: string): boolean {
23     return this.guildData[guild] && this.guildData[guild].token === token;
24     }
25    
26     validToken(token: string): boolean {
27     for (const key in this.guildData) {
28     if (this.guildData[key].token === token)
29     return true;
30     }
31    
32     return false;
33     }
34    
35     registerRoutes() {
36     this.app.all('/', (req: Request, res: Response) => {
37     res.send("Server is up.");
38     });
39    
40     this.app.use('/api', router);
41     }
42    
43     run(port: number = 4000) {
44     this.port = port;
45    
46     this.registerRoutes();
47     this.app.listen(port, () => console.log('Server listening at port ' + this.port));
48     }
49     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26