/
Simulation.ts
46 lines (39 loc) · 1.29 KB
/
Simulation.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { json, urlencoded } from 'body-parser';
import * as express from 'express';
import { Request, Response, NextFunction } from 'express';
import { DynamicSimulationDataInterpreter } from './DynamicSimulationDataInterpreter';
import { TestDynamicInterpreterInteraction } from '../../data/rest/simulation/TestDynamicInterpreterInteraction';
import { DamageInteractions } from '../../data/rest/simulation/DamageInteractions';
import { INTERNAL_SERVER_ERROR } from 'http-status-codes';
/**
* Create Express server.
*/
const app = express();
/**
* Express configuration.
*/
app.use(urlencoded({ extended: true }));
app.use(json());
/**
* Test Route
*/
const testRouter = (req: Request, res: Response) => {
DynamicSimulationDataInterpreter.interpret(TestDynamicInterpreterInteraction, req, res);
};
/**
* Damage Routes
*/
const damageRouter = (req: Request, res: Response) => {
DynamicSimulationDataInterpreter.interpret(DamageInteractions, req, res);
};
/**
* ROUTES registration
*/
app.post('/test/:userid/:anyOtherParam', testRouter);
app.get('/damage/vehicle/:id', damageRouter);
app.use((err: any, req: Request, res: Response, next: NextFunction) => {
// tslint:disable-next-line:no-console
console.error(err);
res.status(INTERNAL_SERVER_ERROR).send();
});
export default app;