workadventure/back/src/App.ts

69 lines
2.8 KiB
TypeScript
Raw Normal View History

// 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/..."
import express from "express";
import {Application, Request, Response} from 'express';
import bodyParser = require('body-parser');
import * as http from "http";
import {MapController} from "./Controller/MapController";
import {PrometheusController} from "./Controller/PrometheusController";
2020-09-17 18:08:20 +02:00
import {AdminController} from "./Controller/AdminController";
import {DebugController} from "./Controller/DebugController";
2020-09-28 18:52:54 +02:00
import {App as uwsApp} from "./Server/sifrr.server";
class App {
2020-09-28 18:52:54 +02:00
public app: uwsApp;
public ioSocketController: IoSocketController;
public authenticateController: AuthenticateController;
public mapController: MapController;
public prometheusController: PrometheusController;
2020-09-17 18:08:20 +02:00
private adminController: AdminController;
private debugController: DebugController;
constructor() {
2020-09-28 18:52:54 +02:00
this.app = new uwsApp();
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);
});
//create socket controllers
2020-09-28 18:52:54 +02:00
this.ioSocketController = new IoSocketController(this.app);
this.authenticateController = new AuthenticateController(this.app);
this.mapController = new MapController(this.app);
this.prometheusController = new PrometheusController(this.app, this.ioSocketController);
2020-09-17 18:08:20 +02:00
this.adminController = new AdminController(this.app);
this.debugController = new DebugController(this.app, this.ioSocketController);
}
// TODO add session user
private config(): void {
2020-09-28 18:52:54 +02:00
/*this.app.use(bodyParser.json());
this.app.use(bodyParser.urlencoded({extended: false}));*/
}
private crossOrigin(){
2020-09-28 18:52:54 +02:00
/*this.app.use((req: Request, res: Response, next) => {
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");
next();
2020-09-28 18:52:54 +02:00
});*/
}
}
2020-09-28 18:52:54 +02:00
export default new App().app;