-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathserver.js
46 lines (39 loc) · 1.16 KB
/
server.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
// Load the express module.
var express = require('express');
var app = express();
var path = require('path');
var step = 1;
var fs = require('fs');
// Load in the config.
let rawconfig = fs.readFileSync('config.json');
let config = JSON.parse(rawconfig);
// Set up the static asset directory.
app.use(express.static('public'));
// Respond to requests for / with index.html.
app.get('/', function(req, res){
res.sendFile(path.join(__dirname, '', 'index.html'));
});
// Respond to requests for /current with current step.
app.get('/current', function(req, res){
res.send(String(step));
});
// Respond to requests for /config with current config.
app.get('/config', function(req, res){
res.send(config);
});
// Allow incrementing or decrementing the step via /up or /down.
app.get('/up', function(req, res){
if (step < config.task_list_items.length){
step++;
}
res.send('New value: ' + step);
});
app.get('/down', function(req, res){
if (step > 1){
step--;
}
res.send('New value: ' + step);
});
// Start listening on configured port.
app.listen(config.server_port);
console.log('Server listening on port ' + config.server_port + '.');