Simplify ATG logPrefix() method
[e-mobility-charging-stations-simulator.git] / src / ui / httpd / start.ts
... / ...
CommitLineData
1import Bootstrap from '../../charging-station/Bootstrap';
2import express from 'express';
3
4const 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>`;
10const pageFooter = '</html>';
11
12const app = express();
13app.disable('x-powered-by');
14
15app.get('/', (request, response) => {
16 response.send(
17 pageHeader +
18 `<body>
19 <form>
20 <input type="button" onclick="window.location.href='/start';" value="Start" />
21 <input type="button" onclick="window.location.href='/stop';" value="Stop" />
22 </form>
23 </body>` +
24 pageFooter
25 );
26});
27
28app.get('/start', (request, response, next) => {
29 Bootstrap.getInstance().start().catch(next);
30 console.info('*** started');
31 response.send(
32 pageHeader + '<body><b>Started</b><br/><a href="/">Return to Top</a></body>' + pageFooter
33 );
34});
35
36app.get('/stop', (request, response, next) => {
37 Bootstrap.getInstance().stop().catch(next);
38 console.info('*** stopped');
39 response.send(
40 pageHeader + '<body><b>Stopped</b><br/><a href="/">Return to Top</a></body>' + pageFooter
41 );
42});
43
44app.listen(process.env.PORT ?? 8080, () =>
45 console.info(`Listening on http://localhost:${process.env.PORT ?? 8080}`)
46);