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