Added start/stop capabilities through http
authorJeff Durnwald <jeff.durnwald@sap.com>
Wed, 6 Apr 2022 12:39:31 +0000 (08:39 -0400)
committerJeff Durnwald <jeff.durnwald@sap.com>
Wed, 6 Apr 2022 12:39:31 +0000 (08:39 -0400)
README.md
package.json
rollup.config.js
src/http/start.ts [new file with mode: 0644]

index af3a0d0c151cd2b191a2636514fb479b0083049c..0a2d921097ff822eba71997f1efce619e37cb3bc 100644 (file)
--- a/README.md
+++ b/README.md
@@ -241,6 +241,9 @@ The syntax is similar to the charging station configuration template 'Configurat
 
 To start the program, run: `npm start`.
 
+To start the program with a UI controller, run: `npm start:server`.
+Then, start/stop the simulator connections by going to `https://<hostname:port>` in a browser.
+
 ## Docker
 
 In the [docker](./docker) folder:
index 74b2c668b2406a5d2e70e1f5bd4645cb089fc4c6..37f0a76768b75bc03098786bc455508bdd4dd71b 100644 (file)
@@ -46,6 +46,7 @@
     "prepare": "node prepare.js",
     "prestart": "npm run build",
     "start": "cross-env NODE_ENV=production node -r source-map-support/register dist/start.js",
+    "start:server": "npm run build && cross-env NODE_ENV=production node -r source-map-support/register dist/http/start.js",
     "start:debug": "cross-env NODE_ENV=production node -r source-map-support/register --inspect dist/start.js",
     "start:dev": "npm run build:dev && cross-env NODE_ENV=development node -r source-map-support/register dist/start.js",
     "start:dev:debug": "npm run build:dev && cross-env NODE_ENV=development node -r source-map-support/register --inspect dist/start.js",
     "@mikro-orm/mariadb": "^4.5.10",
     "@mikro-orm/reflection": "^4.5.10",
     "@mikro-orm/sqlite": "^4.5.10",
+    "@types/express": "^4.17.13",
     "basic-ftp": "^4.6.6",
     "chalk": "^4.1.2",
+    "express": "^4.17.3",
     "mongodb": "^4.4.1",
     "poolifier": "^2.2.0",
     "proper-lockfile": "^4.1.2",
index e086e90909abc0385768a0ba84ed847edf964e0b..ae0e0d905e8e0c01056be21535d8ca77361666e9 100644 (file)
@@ -9,7 +9,7 @@ import ts from 'rollup-plugin-ts';
 const isDevelopmentBuild = process.env.BUILD === 'development';
 
 export default {
-  input: ['src/start.ts', 'src/charging-station/ChargingStationWorker.ts'],
+  input: ['src/start.ts', 'src/http/start.ts', 'src/charging-station/ChargingStationWorker.ts'],
   output: {
     dir: 'dist',
     format: 'cjs',
@@ -23,6 +23,7 @@ export default {
     'basic-ftp',
     'chalk',
     'crypto',
+    'express',
     'fs',
     '@mikro-orm/core',
     '@mikro-orm/reflection',
diff --git a/src/http/start.ts b/src/http/start.ts
new file mode 100644 (file)
index 0000000..7afdd28
--- /dev/null
@@ -0,0 +1,32 @@
+import Bootstrap from '../charging-station/Bootstrap';
+import express from 'express';
+
+const app = express();
+
+app.get('/', (request, response) => {
+  response.send(`
+  <form>
+  <input type="button" onclick="window.location.href='/start';" value="Start" />
+  <input type="button" onclick="window.location.href='/stop';" value="Stop" />
+</form>
+
+  `);
+});
+
+app.get('/start', (request, response, next) => {
+  Bootstrap.getInstance().start().catch(next);
+  console.log('*** started');
+  response.send('<b>Started</b><br/><a href="/">Return to Top</a>');
+});
+
+app.get('/stop', (request, response, next) => {
+  Bootstrap.getInstance().stop().catch(next);
+  console.log('*** stopped');
+  response.send('<b>Stopped</b><br/><a href="/">Return to Top</a>');
+});
+
+app.listen(process.env.PORT ?? 8080, () =>
+  console.log(`Listening on port: ${process.env.PORT ?? 8080}`)
+);