From 175d4f46729bf9ea47d61aa4a6ac69a03cf4cb88 Mon Sep 17 00:00:00 2001 From: Jeff Durnwald Date: Wed, 6 Apr 2022 08:39:31 -0400 Subject: [PATCH] Added start/stop capabilities through http --- README.md | 3 +++ package.json | 3 +++ rollup.config.js | 3 ++- src/http/start.ts | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/http/start.ts diff --git a/README.md b/README.md index af3a0d0c..0a2d9210 100644 --- 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://` in a browser. + ## Docker In the [docker](./docker) folder: diff --git a/package.json b/package.json index 74b2c668..37f0a767 100644 --- a/package.json +++ b/package.json @@ -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", @@ -79,8 +80,10 @@ "@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", diff --git a/rollup.config.js b/rollup.config.js index e086e909..ae0e0d90 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -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 index 00000000..7afdd281 --- /dev/null +++ b/src/http/start.ts @@ -0,0 +1,32 @@ +import Bootstrap from '../charging-station/Bootstrap'; +import express from 'express'; + +const app = express(); + +app.get('/', (request, response) => { + response.send(` + + +
+ + +
+ + `); +}); + +app.get('/start', (request, response, next) => { + Bootstrap.getInstance().start().catch(next); + console.log('*** started'); + response.send('Started
Return to Top'); +}); + +app.get('/stop', (request, response, next) => { + Bootstrap.getInstance().stop().catch(next); + console.log('*** stopped'); + response.send('Stopped
Return to Top'); +}); + +app.listen(process.env.PORT ?? 8080, () => + console.log(`Listening on port: ${process.env.PORT ?? 8080}`) +); -- 2.34.1