mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 18:59:19 +00:00
Added API
This commit is contained in:
@@ -3,6 +3,7 @@ import Configuration from './Configuration';
|
||||
import Prisma from './Prisma';
|
||||
import Discord from './Discord';
|
||||
import osu from './osuAPI';
|
||||
import Express from './Express';
|
||||
|
||||
import Logger from '../libs/Logger';
|
||||
import Locale from './Locale';
|
||||
@@ -41,6 +42,16 @@ class App {
|
||||
Logger.log('info', 'Loading osu! Client');
|
||||
osu.init();
|
||||
}
|
||||
|
||||
public loadExpress(): void {
|
||||
Logger.log('info', 'Loading Express');
|
||||
Express.init();
|
||||
}
|
||||
|
||||
public endExpress(): void {
|
||||
Logger.log('info', 'Ending Express');
|
||||
Express.end();
|
||||
}
|
||||
}
|
||||
|
||||
export default new App();
|
||||
|
||||
@@ -31,6 +31,9 @@ class Environment {
|
||||
const PRIVATE_BOT = process.env.PRIVATE_BOT;
|
||||
const SUPPORT_URL = process.env.SUPPORT_URL;
|
||||
|
||||
const WEB_HOST = process.env.WEB_HOST;
|
||||
const WEB_PORT = process.env.WEB_PORT;
|
||||
|
||||
const OSU_API_KEY = process.env.OSU_API_KEY;
|
||||
const YOUTUBE_COOKIE_BASE64 = process.env.YOUTUBE_COOKIE_BASE64;
|
||||
|
||||
@@ -47,6 +50,9 @@ class Environment {
|
||||
PRIVATE_BOT,
|
||||
SUPPORT_URL,
|
||||
|
||||
WEB_HOST,
|
||||
WEB_PORT,
|
||||
|
||||
OSU_API_KEY,
|
||||
YOUTUBE_COOKIE_BASE64,
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
|
||||
import Logger from "../libs/Logger";
|
||||
import Environment from "./Environment";
|
||||
|
||||
import ExpressException from '../exception/ExpressException';
|
||||
import Routes from './Routes';
|
||||
|
||||
class Express {
|
||||
|
||||
public server: any;
|
||||
public express: express.Application;
|
||||
|
||||
constructor () {
|
||||
this.server = null;
|
||||
this.express = express();
|
||||
}
|
||||
|
||||
public init(): void {
|
||||
|
||||
this.mountMiddlewares();
|
||||
this.mountRoutes();
|
||||
this.express = this.express.use(ExpressException.errorLogger);
|
||||
|
||||
this.server = this.express.listen(Environment.get().WEB_PORT, Environment.get().WEB_HOST, () => {
|
||||
Logger.log('info', `Express Webserver listening at ${Environment.get().WEB_HOST}:${Environment.get().WEB_PORT}`);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public end(): void {
|
||||
if(this.server != null)
|
||||
this.server.close();
|
||||
}
|
||||
|
||||
private mountRoutes (): void {
|
||||
this.express = Routes.mountAPI(this.express);
|
||||
this.express = Routes.mountWeb(this.express);
|
||||
}
|
||||
|
||||
private mountMiddlewares (): void {
|
||||
|
||||
//this.express = RateLimit.init(this.express);
|
||||
this.express = this.express.use(cors());
|
||||
|
||||
//This always have to be at the bottom!
|
||||
this.express = this.express.use(express.json());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default new Express();
|
||||
@@ -0,0 +1,22 @@
|
||||
import express, { Application } from 'express';
|
||||
import Logger from '../libs/Logger';
|
||||
import apiv1Router from '../routes/API/v1';
|
||||
|
||||
class Routes {
|
||||
|
||||
public mountWeb(_express: express.Application): Application {
|
||||
Logger.log('info', 'Mounting Web routes');
|
||||
return _express;
|
||||
}
|
||||
|
||||
public mountAPI(_express: express.Application): Application {
|
||||
Logger.log('info', 'Mounting API routes');
|
||||
|
||||
_express.use('/api/v1/', apiv1Router);
|
||||
|
||||
return _express;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default new Routes;
|
||||
Reference in New Issue
Block a user