-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (46 loc) · 1.13 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
50
51
52
53
54
55
56
57
'use strict';
require('./lib/polyfills');
const Hapi = require('@hapi/hapi');
const Path = require('path');
const { sanitizePath } = require('./lib/utils');
require('dotenv').config();
const adbClient = require('./lib/adb-client');
const init = async () => {
let port = process.env.PORT;
if (port === null || port === "") {
port = 8000;
}
const server = Hapi.server({
port,
host: '0.0.0.0',
routes: {
files: {
relativeTo: Path.join(__dirname, 'public')
}
}
});
await server.register(require('inert'));
server.route({
method: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
path: '/api/{path*}',
handler: adbClient
});
server.route({
method: 'GET',
path: '/',
handler: (request, h) => h.file('index.html')
});
server.route({
method: 'GET',
path: '/{path*}',
handler: (request, h) => h.file(sanitizePath(request.params.path))
});
await server.start();
console.log('Server running on %s', server.info.uri);
};
process.on('unhandledRejection', (err) => {
console.error(err);
process.exit(1);
});
// noinspection JSIgnoredPromiseFromCall
init();