-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
115 lines (99 loc) · 2.98 KB
/
index.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import bodyParser from 'body-parser';
import dotenv from 'dotenv';
import express from 'express';
import swaggerUi from 'swagger-ui-express';
import { GasificationPower } from './gasification-power';
import { GenericCombinedHeatPower } from './generic-combined-heat-power';
import { GenericPowerOnly } from './generic-power-only';
import { Hydrogen } from './hydrogen';
import {
InputModCHP,
InputModGP,
InputModGPO,
InputModHydrogen,
InputModSensitivity,
InputModSubstation,
InputModTransimission,
} from './input.model';
import { runSensitivityAnalysis } from './sensitivity';
import { SubstationCost } from './substation';
import { TransmissionCost } from './transmission';
// tslint:disable-next-line: no-var-requires
const swaggerDocument = require('./swagger.json');
dotenv.config();
const app = express();
app.use(bodyParser.json());
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept'
);
next();
});
const port = process.env.PORT || 3000;
app.post('/genericPowerOnly', async (req: any, res: any) => {
const params: InputModGPO = req.body;
try {
const result = await GenericPowerOnly(params);
res.status(200).json(result);
} catch (e) {
res.status(400).send(e.message);
}
});
app.post('/genericCombinedHeatPower', async (req: any, res: any) => {
const params: InputModCHP = req.body;
try {
const result = await GenericCombinedHeatPower(params);
res.status(200).json(result);
} catch (e) {
res.status(400).send(e.message);
}
});
app.post('/gasificationPower', async (req: any, res: any) => {
const params: InputModGP = req.body;
try {
const result = await GasificationPower(params);
res.status(200).json(result);
} catch (e) {
res.status(400).send(e.message);
}
});
app.post('/hydrogen', async (req: any, res: any) => {
const params: InputModHydrogen = req.body;
try {
const result = await Hydrogen(params);
res.status(200).json(result);
} catch (e) {
res.status(400).send(e.message);
}
});
app.post('/sensitivity', async (req: any, res: any) => {
const params: InputModSensitivity = req.body;
try {
const result = await runSensitivityAnalysis(params);
res.status(200).json(result);
} catch (e) {
res.status(400).send(e.message);
}
});
app.post('/transmission', async (req: any, res: any) => {
const params: InputModTransimission = req.body;
try {
const result = await TransmissionCost(params);
res.status(200).json(result);
} catch (e) {
res.status(400).send(e.message);
}
});
app.post('/substation', async (req: any, res: any) => {
const params: InputModSubstation = req.body;
try {
const result = await SubstationCost(params);
res.status(200).json(result);
} catch (e) {
res.status(400).send(e.message);
}
});
app.use('/', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.listen(port, () => console.log(`Listening on port ${port}!`));