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-04-04 04:08:12 +02:00
|
|
|
import express from "express";
|
2020-04-05 20:57:14 +02:00
|
|
|
import {Application, Request, Response} from 'express';
|
2020-04-04 04:08:12 +02:00
|
|
|
import bodyParser = require('body-parser');
|
|
|
|
import * as http from "http";
|
|
|
|
|
|
|
|
class App {
|
|
|
|
public app: Application;
|
|
|
|
public server: http.Server;
|
|
|
|
public ioSocketController: IoSocketController;
|
2020-04-04 17:22:02 +02:00
|
|
|
public authenticateController: AuthenticateController;
|
2020-04-04 04:08:12 +02:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.app = express();
|
2020-04-04 17:22:02 +02:00
|
|
|
|
|
|
|
//config server http
|
2020-04-04 04:08:12 +02:00
|
|
|
this.config();
|
|
|
|
this.server = http.createServer(this.app);
|
2020-04-04 17:22:02 +02:00
|
|
|
|
|
|
|
//create controllers
|
2020-04-04 04:08:12 +02:00
|
|
|
this.ioSocketController = new IoSocketController(this.server);
|
2020-04-04 17:22:02 +02:00
|
|
|
this.authenticateController = new AuthenticateController(this.app);
|
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 {
|
|
|
|
this.app.use(bodyParser.json());
|
|
|
|
this.app.use(bodyParser.urlencoded({extended: false}));
|
2020-04-29 01:40:32 +02:00
|
|
|
this.app.use((req: Request, res: Response, next) => {
|
2020-04-05 20:57:14 +02:00
|
|
|
res.header("Access-Control-Allow-Origin", "*"); // update to match the domain you will make the request from
|
|
|
|
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
|
|
|
next();
|
|
|
|
});
|
2020-04-04 04:08:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new App().server;
|