-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapp.js
47 lines (38 loc) · 1.19 KB
/
app.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
'use strict'
const Hapi = require('@hapi/hapi')
const Inert = require('inert')
const server = Hapi.server({
port: process.env.PORT || 3000,
host: '0.0.0.0'
})
const start = async () => {
await server.register(Inert)
server.route({
method: 'GET',
path: '/',
handler: (request, h) => {
return h.file('index.html')
}
})
server.route({
method: 'GET',
path: '/{micro_app}/{path*}',
handler: (request, h) => {
const micro_app = request.params.micro_app;
const path = request.params.path;
/* {domain}/*.[js|css] */
if (micro_app.includes('.')) { return h.file(micro_app) }
/* {domain}/{micro_app} */
if (!micro_app.includes('.') && !path) { return h.file('index.html') }
/* {domain}/{micro_app}/{path*} */
if (!micro_app.includes('.') && path && !path.includes('.')) { return h.file('index.html') }
/* {domain}/{micro_app}/*.[js|css] */
if (!micro_app.includes('.') && path && path.includes('.')) { return h.file(`${micro_app}/${path}`) }
/* 404 fallback to foundation app */
return h.file('index.html')
}
})
await server.start()
console.log('Server running at:', server.info.uri)
}
start()