This repository was archived by the owner on Nov 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathwizard.js
More file actions
82 lines (67 loc) · 2.07 KB
/
wizard.js
File metadata and controls
82 lines (67 loc) · 2.07 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
var express = require('express'),
utils = require('./utils.js');
var app = express();
app.set('port', process.env.PORT || 3000);
app.use(express.static(__dirname + '/wizard'));
app.use(express.json());
app.use(express.urlencoded());
var useCases = [];
app.post('/configure/crime-stringer', function(req, res, next) {
res.setHeader('Content-Type', 'application/json; charset=utf-8');
useCases[1] = {
stringer: 'crime-stringer.js',
parameters: [req.body.lat, req.body.lng, req.body.numberOfMonths, req.body.threshold]
};
res.json(true);
});
app.post('/configure/local-police-stringer', function(req, res, next) {
res.setHeader('Content-Type', 'application/json; charset=utf-8');
useCases[0] = {
stringer: 'local-police-stringer.js',
parameters: [req.body.force, req.body.neighbourhood]
};
res.json(true);
});
app.post('/configure/write', function(req, res, next) {
res.setHeader('Content-Type', 'application/json; charset=utf-8');
utils.writeAsset('stringers_use_cases.json', JSON.stringify(useCases, null, 2),
function(err) {
if (err) {
res.json(false);
}
else {
res.json(true);
}
});
});
app.post('/configure/user-email', function(req, res, next) {
res.setHeader('Content-Type', 'application/json; charset=utf-8');
utils.writeAsset('user-email.json', req.body.user_email, function(err) {
if (err) {
res.json(false);
}
else {
res.json(true);
}
});
});
app.get('/configuration', function(req, res, next) {
res.setHeader('Content-Type', 'application/json; charset=utf-8');
utils.readAsset('stringers_use_cases.json', function(err, asset) {
res.send(asset);
});
});
app.listen(app.get('port'), function() {
console.log('Server started on port %d', app.get('port'));
});
process.on('uncaughtException', function(err) {
if (err.errno === 'EADDRINUSE') {
console.log('Unable to start server on port %d (is something already running on that port?)', app.get('port'));
} else {
console.log(err);
}
process.exit(1);
});
process.on('SIGINT', function () {
process.exit(0);
});