Migrating to uWS

This commit is contained in:
David Négrier 2020-09-28 18:52:54 +02:00
parent 783d58d3cb
commit 6a4c0c8678
31 changed files with 2056 additions and 1123 deletions

View file

@ -9,10 +9,10 @@ import {MapController} from "./Controller/MapController";
import {PrometheusController} from "./Controller/PrometheusController";
import {AdminController} from "./Controller/AdminController";
import {DebugController} from "./Controller/DebugController";
import {App as uwsApp} from "./Server/sifrr.server";
class App {
public app: Application;
public server: http.Server;
public app: uwsApp;
public ioSocketController: IoSocketController;
public authenticateController: AuthenticateController;
public mapController: MapController;
@ -21,18 +21,25 @@ class App {
private debugController: DebugController;
constructor() {
this.app = express();
//config server http
this.server = http.createServer(this.app);
this.app = new uwsApp();
this.config();
this.crossOrigin();
//TODO add middleware with access token to secure api
// 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
this.ioSocketController = new IoSocketController(this.server);
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);
@ -42,20 +49,20 @@ class App {
// TODO add session user
private config(): void {
this.app.use(bodyParser.json());
this.app.use(bodyParser.urlencoded({extended: false}));
/*this.app.use(bodyParser.json());
this.app.use(bodyParser.urlencoded({extended: false}));*/
}
private crossOrigin(){
this.app.use((req: Request, res: Response, next) => {
/*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();
});
});*/
}
}
export default new App().server;
export default new App().app;