-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
86 lines (75 loc) · 2.53 KB
/
server.js
File metadata and controls
86 lines (75 loc) · 2.53 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
////////////////////////////////////////////////////////
// Setup
////////////////////////////////////////////////////////
// import libraries
'use strict';
var fs = require('fs'),
express = require('express'),
bodyParser = require('body-parser'),
path = require('path'),
sys = require('util'),
app = express(),
server = require('http').createServer(app),
io = require('socket.io')(server);
// can read JSON files from post requests
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
// reading json files
var currentPath = process.cwd();
var dataFolder = currentPath + '/data/';
// var gpusJSON = JSON.parse(fs.readFileSync(dataFolder + 'gpus.json', 'utf8'));
// view engine
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// set static folder
app.use('/', express.static(__dirname + '/public/'));
////////////////////////////////////////////////////////
// Define routes:
////////////////////////////////////////////////////////
// home page
app.get('/', (req, res) => {
res.render('home');
});
// // info page
// app.get('/info', (req, res) => {
// if(req.query.project in mappingProjectsIdxJSON){
// res.render('info', {
// projects: projectsJSON,
// gpus: gpusJSON,
// project: projectsJSON[mappingProjectsIdxJSON[req.query.project]],
// page: "info"
// });
// }
// else{
// res.redirect('/');
// }
// });
// // info page post to demo page
// app.post('/info', (req, res) => {
// res.redirect('demo?project='+req.query.project+
// '&session='+req.query.session+
// '&gpu1='+req.body.gpu1+
// '&gpu2='+req.body.gpu2+
// '&gpu1Progress='+mappingGpusProgressJSON[req.body.gpu1+mappingProjectsIdxJSON[req.query.project]]+
// '&gpu2Progress='+mappingGpusProgressJSON[req.body.gpu2+mappingProjectsIdxJSON[req.query.project]]
// );
// console.log(req.query.project);
// console.log(req.query.session);
// console.log(req.body.gpu1);
// console.log(req.body.gpu2);
// });
// when user try to access any other page, error webpage
app.get('*', (req, res) => {
res.render('404');
});
////////////////////////////////////////////////////////
// WebSocket
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// Running Server
////////////////////////////////////////////////////////
server.listen(8080, () => {
console.info('==> 🌎 Go to http://localhost:8080');
});