Code cleanups
[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 app = express();
5
6 app.get('/', (request, response) => {
7 response.send(`
8
9 <form>
10 <input type="button" onclick="window.location.href='/start';" value="Start" />
11 <input type="button" onclick="window.location.href='/stop';" value="Stop" />
12 </form>
13
14 `);
15 });
16
17 app.get('/start', (request, response, next) => {
18 Bootstrap.getInstance().start().catch(next);
19 console.log('*** started');
20 response.send('<b>Started</b><br/><a href="/">Return to Top</a>');
21 });
22
23 app.get('/stop', (request, response, next) => {
24 Bootstrap.getInstance().stop().catch(next);
25 console.log('*** stopped');
26 response.send('<b>Stopped</b><br/><a href="/">Return to Top</a>');
27 });
28
29 app.listen(process.env.PORT ?? 8080, () =>
30 console.log(`Listening on port: ${process.env.PORT ?? 8080}`)
31 );