forked from DEIS-Tools/VisuAalWiNes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (50 loc) · 1.94 KB
/
app.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
57
const express = require('express');
const app = express();
const path = require('path');
const http = require('http').createServer(app);
const io = require('socket.io')(http);
console.log('VisuAalWiNes - Visualization for AaalWiNes');
console.log(' Version 0.3.0');
const modelsPath = path.join(process.cwd(), 'data', 'models');
const binPath = path.join(process.cwd(), 'bin');
const models = require('./backend/models')(modelsPath, binPath, models => {
io.emit('models', models);
});
app.use(express.static(path.join(__dirname, 'static')));
io.on('connect', (socket) => {
socket.on('getModelData', async (name) => {
try {
const modelData = await models.loadModel(name);
socket.emit('modelData', { name: name, data: modelData });
} catch (err) {
socket.emit('modelData', { name: name, error: err.toString() });
}
});
socket.on('doQuery', async (model, query, options) => {
try {
const queryResult = await models.doQuery(socket, model, query, options);
socket.emit('queryResult', { model: model, query: query, data: queryResult });
} catch (err) {
socket.emit('queryResult', { model: model, query: query, error: err.toString() });
}
});
socket.on('cancelQuery', async () => {
models.cancelQuery(socket);
});
socket.on('uploadModel', async (data) => {
try {
const [name, modelData] = await models.uploadModel(data);
socket.emit('modelDataAfterUpload', { name: name, data: modelData });
} catch (err) {
socket.emit('modelDataAfterUpload', { error: err.toString() });
}
});
socket.emit('models', models.models);
});
app.use(function(req, res) {
res.status(400).sendFile(path.join(__dirname,'static', '404.html'));
});
http.listen(3000, function() {
console.log();
console.log('Start your browser and go to http://localhost:3000/');
});