import * as express from 'express'; import { ConfigurationHelper, conf } from "./helpers/ConfigHelper"; import { DatabaseHelper } from "./helpers/DatabaseHelper"; import { Routes, RouteType } from './controllers/Routes'; import { RequestHandler } from './models/RequestHandler'; /** * Main project script * * @author Pierre HUBERT */ console.info("Comunic API v6\t@author Pierre HUBERT\t2019-" + new Date().getFullYear()); async function init() { console.info("Load configuration..."); ConfigurationHelper.loadConf("config.json"); console.info("Connect to database"); await DatabaseHelper.connect(); // Start HTTP Server const app = express(); // Process the list of routes Routes.forEach(route => { if(route.type == RouteType.GET) app.get(route.path, (req : express.Request, res : express.Response)=> { route.cb(new RequestHandler(req, res)); }) }) app.listen(conf().port, () => { console.info("Started server on http://127.0.0.1:" + conf().port); }); } init();