-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
81 lines (68 loc) · 1.89 KB
/
main.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict';
const Hapi = require('@hapi/hapi');
const program = require('commander');
if ( global.v8debug) {
global.v8debug.Debug.setBreakOnException(); // enable it, global.v8debug is only defined when the --debug or --debug-brk flag is set
}
async function start(options)
{
var app = require('./js/application.js');
app.init(options);
const server = new Hapi.Server({ port: 3000});
server.application_ = app;
await server.register(require('@hapi/inert'));
// set up static routes
server.route({
method: 'GET',
path: '/',
handler: function (request, h) {
return h.file('public/index-edit.html');
}
});
server.route({
method: 'GET',
path: '/{file*}',
handler: {
directory: {
path: 'public'
}
}
});
server.route({
method: 'GET',
path: '/grammar.txt',
handler: function (request, h) {
return h.file('grammar.txt');
}
});
// route command url to the parser
server.route({
method: 'GET',
path: '/command',
handler: function (request, reply) {
var input = request.url.searchParams.get('command');
var response;
try {
var result = request.server.application_.parse(input);
response = { reply: result};
}
catch(err)
{
console.log(err);
console.log(err.stack);
response = { reply: "*error*: " + err.message };
}
return(response);
}
});
await server.start();
console.log('Server running at:', server.info.uri);
}
// Initialisation
program
.version('0.0.1')
.option('-m, --midi-device <midiDevice>', 'selects a midi interface')
.option('-s, --midi-sync <midiDevice>', 'selects a midi device to sync from')
.option('-c, --cycle <cycleString>', 'use the specied cycleString at startup');
program.parse(process.argv);
start(program.opts());