2018-01-01 18:56:07 +00:00
|
|
|
/*
|
|
|
|
* Stairs
|
|
|
|
* Copyright 2017 (c) Mark van Renswoude
|
|
|
|
*
|
|
|
|
* https://git.x2software.net/pub/Stairs
|
|
|
|
*/
|
|
|
|
const express = require('express');
|
2018-01-07 22:12:42 +00:00
|
|
|
const bodyParser = require('body-parser');
|
|
|
|
|
2018-01-01 18:56:07 +00:00
|
|
|
const app = express();
|
|
|
|
|
2018-01-07 22:12:42 +00:00
|
|
|
app.use(bodyParser.json());
|
2018-01-01 18:56:07 +00:00
|
|
|
app.use(express.static('web'));
|
|
|
|
app.use(express.static('web/dist'));
|
|
|
|
|
|
|
|
app.get('/api/version', function(req, res)
|
|
|
|
{
|
|
|
|
res.send({
|
|
|
|
systemID: 'dev-server',
|
|
|
|
version: 'dev-server'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
app.get('/api/connection', function(req, res)
|
|
|
|
{
|
|
|
|
res.send({
|
|
|
|
hostname: 'dev-server',
|
|
|
|
accesspoint: true,
|
|
|
|
station: true,
|
|
|
|
ssid: 'MyWiFiSSID',
|
|
|
|
password: 'supersecret',
|
|
|
|
dhcp: true,
|
|
|
|
ip: '192.168.1.234',
|
|
|
|
subnetmask: '255.255.255.0',
|
|
|
|
gateway: '192.168.1.0'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
app.get('/api/connection/status', function(req, res)
|
|
|
|
{
|
|
|
|
res.send({
|
|
|
|
"ap": {
|
|
|
|
"enabled": true,
|
|
|
|
"ip": "192.168.4.1"
|
|
|
|
},
|
|
|
|
"station": {
|
|
|
|
"enabled": true,
|
|
|
|
"status": 1,
|
|
|
|
"ip": "0.0.0.0"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
app.post('/api/connection', function(req, res)
|
|
|
|
{
|
|
|
|
res.sendStatus(200);
|
|
|
|
});
|
|
|
|
|
2018-01-07 22:12:42 +00:00
|
|
|
app.post('/api/firmware', function(req, res)
|
|
|
|
{
|
|
|
|
res.sendStatus(200);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var steps = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
|
|
|
|
|
|
app.get('/api/steps', function(req, res)
|
|
|
|
{
|
|
|
|
res.send(steps);
|
|
|
|
});
|
|
|
|
|
|
|
|
app.post('/api/steps', function(req, res)
|
|
|
|
{
|
|
|
|
var body = req.body;
|
|
|
|
if (body && body.hasOwnProperty('values'))
|
|
|
|
{
|
|
|
|
for (var i = 0; i < Math.min(steps.length, body.values.length); i++)
|
|
|
|
steps[i] = parseInt(body.values[i], 10) || 0;
|
|
|
|
|
|
|
|
res.sendStatus(200);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res.sendStatus(400);
|
|
|
|
});
|
|
|
|
|
2018-01-08 15:27:04 +00:00
|
|
|
|
2018-01-01 18:56:07 +00:00
|
|
|
app.listen(3000, function()
|
|
|
|
{
|
|
|
|
console.log('Development server listening on port 3000')
|
|
|
|
console.log('Press Ctrl-C to stop')
|
|
|
|
});
|