2020-04-04 04:08:12 +02:00
|
|
|
// lib/app.ts
|
2020-04-05 14:31:49 +02:00
|
|
|
import {IoSocketController} from "./Controller/IoSocketController"; //TODO fix import by "_Controller/..."
|
|
|
|
import {AuthenticateController} from "./Controller/AuthenticateController"; //TODO fix import by "_Controller/..."
|
2020-05-09 17:50:47 +02:00
|
|
|
import {MapController} from "./Controller/MapController";
|
2020-06-09 11:49:23 +02:00
|
|
|
import {PrometheusController} from "./Controller/PrometheusController";
|
2020-09-17 18:08:20 +02:00
|
|
|
import {AdminController} from "./Controller/AdminController";
|
2020-09-25 13:48:02 +02:00
|
|
|
import {DebugController} from "./Controller/DebugController";
|
2020-09-28 18:52:54 +02:00
|
|
|
import {App as uwsApp} from "./Server/sifrr.server";
|
2020-04-04 04:08:12 +02:00
|
|
|
|
|
|
|
class App {
|
2020-09-28 18:52:54 +02:00
|
|
|
public app: uwsApp;
|
2020-04-04 04:08:12 +02:00
|
|
|
public ioSocketController: IoSocketController;
|
2020-04-04 17:22:02 +02:00
|
|
|
public authenticateController: AuthenticateController;
|
2020-05-09 17:50:47 +02:00
|
|
|
public mapController: MapController;
|
2020-06-09 11:49:23 +02:00
|
|
|
public prometheusController: PrometheusController;
|
2020-09-17 18:08:20 +02:00
|
|
|
private adminController: AdminController;
|
2020-09-25 15:25:06 +02:00
|
|
|
private debugController: DebugController;
|
2020-04-04 04:08:12 +02:00
|
|
|
|
|
|
|
constructor() {
|
2020-09-28 18:52:54 +02:00
|
|
|
this.app = new uwsApp();
|
2020-04-04 17:22:02 +02:00
|
|
|
|
2020-05-10 17:31:27 +02:00
|
|
|
this.config();
|
|
|
|
this.crossOrigin();
|
|
|
|
|
|
|
|
//TODO add middleware with access token to secure api
|
|
|
|
|
2020-09-28 18:52:54 +02:00
|
|
|
// STUPID CORS IMPLEMENTATION.
|
|
|
|
// TODO: SECURE THIS
|
|
|
|
this.app.any('/*', (res, req) => {
|
|
|
|
res.writeHeader('access-control-allow-headers', 'Origin, X-Requested-With, Content-Type, Accept');
|
|
|
|
res.writeHeader('access-control-allow-methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
|
|
|
|
res.writeHeader('access-control-allow-origin', '*');
|
|
|
|
|
|
|
|
req.setYield(true);
|
|
|
|
});
|
|
|
|
|
2020-05-09 17:50:47 +02:00
|
|
|
//create socket controllers
|
2020-09-28 18:52:54 +02:00
|
|
|
this.ioSocketController = new IoSocketController(this.app);
|
2020-04-04 17:22:02 +02:00
|
|
|
this.authenticateController = new AuthenticateController(this.app);
|
2020-05-09 17:50:47 +02:00
|
|
|
this.mapController = new MapController(this.app);
|
2020-06-09 11:49:23 +02:00
|
|
|
this.prometheusController = new PrometheusController(this.app, this.ioSocketController);
|
2020-09-17 18:08:20 +02:00
|
|
|
this.adminController = new AdminController(this.app);
|
2020-09-25 13:48:02 +02:00
|
|
|
this.debugController = new DebugController(this.app, this.ioSocketController);
|
2020-04-04 04:08:12 +02:00
|
|
|
}
|
|
|
|
|
2020-04-04 17:22:02 +02:00
|
|
|
// TODO add session user
|
2020-04-04 04:08:12 +02:00
|
|
|
private config(): void {
|
2020-09-28 18:52:54 +02:00
|
|
|
/*this.app.use(bodyParser.json());
|
|
|
|
this.app.use(bodyParser.urlencoded({extended: false}));*/
|
2020-05-10 17:31:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private crossOrigin(){
|
2020-09-28 18:52:54 +02:00
|
|
|
/*this.app.use((req: Request, res: Response, next) => {
|
2020-05-10 17:31:27 +02:00
|
|
|
res.setHeader("Access-Control-Allow-Origin", "*"); // update to match the domain you will make the request from
|
|
|
|
// Request methods you wish to allow
|
|
|
|
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
|
|
|
|
// Request headers you wish to allow
|
|
|
|
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
2020-04-05 20:57:14 +02:00
|
|
|
next();
|
2020-09-28 18:52:54 +02:00
|
|
|
});*/
|
2020-04-04 04:08:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-28 18:52:54 +02:00
|
|
|
export default new App().app;
|