1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 21:39:22 +00:00
comunicapiv2/src/main.ts

40 lines
1005 B
TypeScript
Raw Normal View History

2019-11-21 17:06:50 +00:00
import * as express from 'express';
import { ConfigurationHelper, conf } from "./helpers/ConfigHelper";
2019-11-21 16:35:56 +00:00
import { DatabaseHelper } from "./helpers/DatabaseHelper";
2019-11-21 17:06:50 +00:00
import { Routes, RouteType } from './controllers/Routes';
import { RequestHandler } from './models/RequestHandler';
2019-11-21 15:28:48 +00:00
2019-11-21 15:08:52 +00:00
/**
* Main project script
*
* @author Pierre HUBERT
*/
2019-11-21 15:28:48 +00:00
console.info("Comunic API v6\t@author Pierre HUBERT\t2019-" + new Date().getFullYear());
2019-11-21 15:08:52 +00:00
2019-11-21 16:37:30 +00:00
async function init() {
console.info("Load configuration...");
ConfigurationHelper.loadConf("config.json");
2019-11-21 16:35:56 +00:00
2019-11-21 16:37:30 +00:00
console.info("Connect to database");
await DatabaseHelper.connect();
2019-11-21 17:06:50 +00:00
// 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);
});
2019-11-21 16:37:30 +00:00
}
init();