quick proxy test

This commit is contained in:
proddy
2021-04-01 17:49:43 +02:00
parent 3bacfc3361
commit d553542206
12 changed files with 3212 additions and 191 deletions

2864
api/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

16
api/package.json Normal file
View File

@@ -0,0 +1,16 @@
{
"name": "api",
"version": "1.0.0",
"description": "mock api for EMS-ESP",
"main": "server.js",
"scripts": {
"dev": "nodemon ./server.js localhost 3080",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "proddy",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"nodemon": "^2.0.4"
}
}

84
api/server.js Normal file
View File

@@ -0,0 +1,84 @@
const ENDPOINT_ROOT = "/rest/";
const FEATURES_ENDPOINT = ENDPOINT_ROOT + "features";
const NTP_STATUS_ENDPOINT = ENDPOINT_ROOT + "ntpStatus";
const NTP_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "ntpSettings";
const TIME_ENDPOINT = ENDPOINT_ROOT + "time";
const AP_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "apSettings";
const AP_STATUS_ENDPOINT = ENDPOINT_ROOT + "apStatus";
const SCAN_NETWORKS_ENDPOINT = ENDPOINT_ROOT + "scanNetworks";
const LIST_NETWORKS_ENDPOINT = ENDPOINT_ROOT + "listNetworks";
const NETWORK_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "networkSettings";
const NETWORK_STATUS_ENDPOINT = ENDPOINT_ROOT + "networkStatus";
const OTA_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "otaSettings";
const UPLOAD_FIRMWARE_ENDPOINT = ENDPOINT_ROOT + "uploadFirmware";
const MQTT_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "mqttSettings";
const MQTT_STATUS_ENDPOINT = ENDPOINT_ROOT + "mqttStatus";
const SYSTEM_STATUS_ENDPOINT = ENDPOINT_ROOT + "systemStatus";
const SIGN_IN_ENDPOINT = ENDPOINT_ROOT + "signIn";
const VERIFY_AUTHORIZATION_ENDPOINT = ENDPOINT_ROOT + "verifyAuthorization";
const SECURITY_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "securitySettings";
const RESTART_ENDPOINT = ENDPOINT_ROOT + "restart";
const FACTORY_RESET_ENDPOINT = ENDPOINT_ROOT + "factoryReset";
const express = require('express');
const path = require('path');
const app = express(),
bodyParser = require("body-parser");
const port = process.env.PORT || 3080;
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, '../interface/build')));
app.get(FEATURES_ENDPOINT, (req, res) => {
// const stuff = req.body.stuff;
console.log('features')
res.json({
security: false,
project: false,
mqtt: false,
ntp: false,
ota: false,
upload_firmware: false
});
});
app.get(VERIFY_AUTHORIZATION_ENDPOINT, (req, res) => {
console.log('verifyAuthentication')
res.json({
access_token: '1234'
});
});
app.get(NETWORK_STATUS_ENDPOINT, (req, res) => {
console.log('networkStatus')
res.json({
status: 3,
local_ip: '10.10.10.2',
mac_address: '00:11:22:33:44',
rssi: 12,
ssid: "myWifi",
bssid: "adsfds",
channel: 3,
submnet_mask: "255.255.255.0"
});
});
app.get(NETWORK_SETTINGS_ENDPOINT, (req, res) => {
console.log('networkSettings')
res.json({
ssid: "myWifi",
password: 'myPassword',
hostname: 'ems-esp',
static_ip_config: false
});
});
app.listen(port);
console.log(`Server listening on port::${port}`);