-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.mjs
55 lines (46 loc) · 1.04 KB
/
index.mjs
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
import hapi from '@hapi/hapi';
import inert from '@hapi/inert';
import path from 'path';
import { fileURLToPath } from 'url';
const fileName = fileURLToPath(import.meta.url);
const dirName = path.dirname(fileName);
const PORT = process.env.PORT || 616;
(async () => {
const server = hapi.server({
port: PORT,
host: '0.0.0.0',
routes: {
files: {
relativeTo: path.join(dirName, 'dist'),
},
},
});
await server.register(inert);
// Chromecast receiver
server.route({
method: 'GET',
path: '/receiver',
handler: {
file: 'receiver.html',
},
});
server.route({
method: 'GET',
path: '/{param*}',
handler: {
directory: {
path: '.',
redirectToSlash: false,
},
},
});
server.ext('onPreResponse', (req, h) => {
const { response } = req;
if (response.isBoom && response.output.statusCode === 404) {
return h.file('index.html');
}
return h.continue;
});
await server.start();
console.log('Tepache Web running at', PORT);
})();