7ff8079a60a4e0001cf8d624dc179e13349cead0
[e-mobility-charging-stations-simulator.git] / src / ui / httpd / start.ts
1 import Bootstrap from '../../charging-station/Bootstrap';
2 import express from 'express';
3
4 const pageHeader = `
5 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
6 "http://www.w3.org/TR/html4/strict.dtd">
7 <html>
8 <head>
9 </head>`;
10 const pageFooter = '</html>';
11
12 const app = express();
13
14 app.get('/', (request, response) => {
15 response.send(
16 pageHeader +
17 `<body>
18 <form>
19 <input type="button" onclick="window.location.href='/start';" value="Start" />
20 <input type="button" onclick="window.location.href='/stop';" value="Stop" />
21 </form>
22 </body>` +
23 pageFooter
24 );
25 });
26
27 app.get('/start', (request, response, next) => {
28 Bootstrap.getInstance().start().catch(next);
29 console.info('*** started');
30 response.send(
31 pageHeader + '<body><b>Started</b><br/><a href="/">Return to Top</a></body>' + pageFooter
32 );
33 });
34
35 app.get('/stop', (request, response, next) => {
36 Bootstrap.getInstance().stop().catch(next);
37 console.info('*** stopped');
38 response.send(
39 pageHeader + '<body><b>Stopped</b><br/><a href="/">Return to Top</a></body>' + pageFooter
40 );
41 });
42
43 app.listen(process.env.PORT ?? 8080, () =>
44 console.info(`Listening on http://localhost:${process.env.PORT ?? 8080}`)
45 );