| 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 | app.disable('x-powered-by'); |
| 14 | |
| 15 | app.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 | |
| 28 | app.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 | |
| 36 | app.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 | |
| 44 | app.listen(process.env.PORT ?? 8080, () => |
| 45 | console.info(`Listening on http://localhost:${process.env.PORT ?? 8080}`) |
| 46 | ); |