hestia/websvr.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-12-19 18:07:36 +00:00
/* Pellet Stove Control Panel
* Web Configuration Server
* v0.0.0 by Skylar Grant
2022-12-20 02:55:50 +00:00
*
* TODOs:
* Implement Express to make it easier
* Add actual data into the responses
2022-12-19 18:07:36 +00:00
*/
2022-12-20 19:18:24 +00:00
const express = require('express');
const app = express();
2022-12-19 18:07:36 +00:00
const http = require('http');
2022-12-20 19:18:24 +00:00
const server = http.createServer(app);
2022-12-19 18:07:36 +00:00
const config = require('./config.json');
2022-12-20 20:17:38 +00:00
const fs = require('fs');
2022-12-21 02:12:22 +00:00
// const bodyParser = require('body-parser');
const core = require('./main.js');
const fn = require('./functions.js');
const gpio = require('rpi-gpio');
app.use(express.urlencoded());
2022-12-20 20:17:38 +00:00
app.use(express.static(__dirname + '/www/public'));
app.set('views', __dirname + '/www/views');
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.get('/', (req, res) => {
fs.readFile(__dirname + '/config.json', (err, data) => {
// console.log(JSON.parse(data));
res.render('index', JSON.parse(data));
// res.send(200);
});
console.log(req);
});
2022-12-19 18:07:36 +00:00
2022-12-20 19:18:24 +00:00
app.post('/', (req, res) => {
2022-12-21 02:12:22 +00:00
fs.readFile(__dirname + '/config.json', (err, data) => {
// console.log(JSON.parse(data));
res.render('index', JSON.parse(data));
if (req.body.start != undefined) {
core.main(fn, gpio);
}
// res.send(200);
});
console.log(req.body);
2022-12-20 19:18:24 +00:00
});
2022-12-19 18:07:36 +00:00
2022-12-20 19:18:24 +00:00
server.listen(config.web.port, config.web.ip);