updated mock doc

This commit is contained in:
Proddy
2022-07-23 13:03:42 +02:00
parent 3b86d1b5aa
commit d5e19fdf5b
2 changed files with 3 additions and 39 deletions

View File

@@ -1,40 +1,5 @@
(<https://github.com/emsesp/EMS-ESP32/issues/41>)
(Based on <https://github.com/emsesp/EMS-ESP32/issues/41>)
When developing and testing the web interface, it's handy not to bother with re-flashing an ESP32 each time. The idea is to mimic the ESP using a mock/stub server that responds to the REST (HTTP POST & GET) and WebSocket calls.
To set it up it do
```sh
% cd mock-api
% npm install
% cd interface
% npm install
```
and to run it
```sh
% cd interface
% npm run standalone
```
## Notes
- new file `interface/src/setupProxy.js`
- new files `mock-api/server.js` with the hardcoded data. Requires its own npm packages for express
## Testing
```bash
% curl -i http://localhost:3080/rest/emsespSettings
```
or from a browser use port 3000 since `setupProxy.js` is redirecting, like http://172.22.227.82:3000/rest/emsespSettings
http://172.22.227.82:3090/es/log?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiYWRtaW4iOnRydWUsInZlcnNpb24iOiIzLjAuMmIwIn0.MsHSgoJKI1lyYz77EiT5ZN3ECMrb4mPv9FNy3udq0TU
Testing the EventSource/SSE use http://172.22.227.82:3090/es/log
## To Do
- add filter rule to prevent from exposing yourself to malicious attacks when running the dev server(<https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a>)
To set it up it do run `npm install` in the `mock-api` folder, then from the `interface` folder run `npm run standalone`. This will start the mock API server on port 3080 using data from `mock-api/server.js` and the web server runs on port 3000.

View File

@@ -1132,7 +1132,7 @@ rest_server.post(EMSESP_BOARDPROFILE_ENDPOINT, (req, res) => {
// EMS-ESP API specific
const emsesp_info = {
System: {
version: '3.x.x',
version: '3.4.2',
uptime: '001+06:40:34.018',
'uptime (seconds)': 110434,
freemem: 131,
@@ -1224,7 +1224,6 @@ rest_server.get(GET_CUSTOMIZATIONS_ENDPOINT, (req, res) => {
// start server
const expressServer = rest_server.listen(port, () =>
console.log(`Mock server for EMS-ESP is up and running at http://localhost:${port}`),
)
console.log(`EMS-ESP Rest API listening to http://localhost:${port}/api`)