This repository has been archived by the owner on Nov 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
49 lines (41 loc) · 1.57 KB
/
index.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
const express = require('express');
const path = require('path');
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);
function serve(where, what) {
app.get(where, (req, res) => {
res.sendFile(path.join(__dirname, what));
});
};
// For static files, we will return them.
app.use(express.static(path.join(__dirname, 'public')));
serve('/lib/svm/svm.js', 'node_modules/svm/lib/svm.js');
serve('/train/indoor.json', 'datasets/sml2010/internalTrainingSet.json');
serve('/train/outdoor.json', 'datasets/sml2010/externalTrainingSet.json');
serve('/test/indoor.json', 'datasets/sml2010/internalTestSet.json');
serve('/test/outdoor.json', 'datasets/sml2010/externalTestSet.json');
serve('/validate/indoor.json', 'datasets/sml2010/internalValidationSet.json');
serve('/validate/outdoor.json', 'datasets/sml2010/externalValidationSet.json');
app.get('/siemens', (req, res) => {
res.sendFile(path.join(__dirname, 'public/index2.html'));
});
app.get('/charts', (req, res) => {
res.sendFile(path.join(__dirname, 'public/charts.html'));
});
// For anything else, we will return index.html as is common with
// single page apps.
app.use((req, res) => {
res.sendFile(path.join(__dirname, 'public/index.html'));
});
// Socket io
io.on('connection', (socket) => {
console.log('socket.io: User connected');
socket.on('test message', (msg) => {
console.log('socket.io: test message: ' + msg);
io.emit('test message', 'Node server says: Hello!');
});
});
http.listen(8080, () => {
console.log('Listening in http://localhost:8080');
});