-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebserver.js
52 lines (40 loc) · 1.27 KB
/
webserver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class Webserver {
constructor(config) {
this.config = config;
this.data = {man_turn_on_until: new Date}
}
refresh_parameters(all_prices, charging_hours, all_prices_night){
this.data = {
config: this.config,
all_prices: all_prices,
charging_hours: charging_hours,
all_prices_night: all_prices_night
};
this.server.close();
this.start();
}
get_man_turn_on_until(){
return this.data.man_turn_on_until;
}
start(){
const haml = require('hamljs');
const fs = require('fs');
const express = require('express');
const app = express();
const port = this.config.port_webserver
const data = this.data
var webserver = this
app.get('/', function (req, res) {
if(req.query.turn_on_hours){
var man_turn_on_until = new Date();
man_turn_on_until.addHours(req.query.turn_on_hours)
webserver.data.man_turn_on_until = man_turn_on_until;
}
var hamlView = fs.readFileSync('views/home.haml', 'utf8');
res.end(haml.render(hamlView, {locals: data}) )
})
app.use('/css', express.static(__dirname + '/node_modules/bootstrap/dist/css'));
this.server = app.listen(port, () => console.log(`listening on port ${port}!`));
}
}
module.exports = Webserver;