-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
56 lines (43 loc) · 1.15 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
47
48
49
50
51
52
53
54
55
56
const express = require('express');
var bodyParser = require('body-parser');
const serverport = 3000;
var state = 'lobby';
const app = express();
// for parsing application/json
app.use(bodyParser.json());
// for parsing application/xwww-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));
app.use('/vr', express.static('vr-public'));
app.use('/app', express.static('app-public'));
app.get('/api/test', (req, res) => {
res.send('Hi this is working.');
});
app.get('/', function(req, res) {
res.redirect('/vr/index.html');
});
app.get('/m', function(req, res) {
res.redirect('/app/index.html');
});
app.get('/api', function(req, res) {
res.send(state);
});
app.post('/api', function(req, res) {
console.log(req.body);
state = req.body.state;
res.send('received');
console.log(state);
});
/*
app.get('/api/brainwaves', (req, res) => {
var now = new Date();
if (now - lastFocus < 5000) {
data.focusLastFiveSeconds = 1;
} else {
data.focusLastFiveSeconds = 0;
}
res.json(data);
});
*/
app.listen(serverport, function() {
console.log('server listening on port ' + serverport);
});