-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.mjs
More file actions
107 lines (84 loc) · 1.95 KB
/
app.mjs
File metadata and controls
107 lines (84 loc) · 1.95 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import debug from 'debug'
import path from 'path'
import nconf from 'nconf'
import Hapi from '@hapi/hapi'
import inert from '@hapi/inert'
import vision from '@hapi/vision'
import Handlebars from 'handlebars'
import {
renderToString
} from '@sequencemedia/react-render'
import config from './server/config/index.mjs'
import IndexPage from './client/components/index-page/index.cjs'
const {
env: {
DEBUG = 'react-select-element-io'
} = {}
} = process
debug.enable(DEBUG)
const log = debug('react-select-element-io')
log('`react-select-element-io` is awake')
const modulePath = process.cwd()
const serverPath = path.resolve(modulePath, 'server')
const publicPath = path.resolve(modulePath, 'public')
const assetsPath = path.resolve(publicPath, 'assets')
nconf
.argv().env()
.defaults(config)
async function start ({ host = 'localhost', port = 5000 } = {}) {
const server = Hapi.server({ host, port })
server.events.on('start', () => {
const {
info
} = server
log(info)
})
server.events.on('stop', () => {
const {
info
} = server
log(info)
})
await server.register([inert, vision])
server.views({
relativeTo: modulePath,
path: path.join(serverPath, 'views'),
engines: {
html: {
module: Handlebars,
compileMode: 'sync',
compileOptions: {
isCached: true
}
}
}
})
server.route([
{
method: 'GET',
path: '/favicon.ico',
handler (request, h) {
return h.redirect('/assets/favicon.ico')
}
},
{
method: 'GET',
path: '/assets/{path*}',
handler: {
directory: {
path: path.normalize(assetsPath),
listing: false,
index: false
}
}
}, {
method: '*',
path: '/',
handler (req, h) {
return h.view('index', { app: renderToString(IndexPage) })
}
}
])
await server.start()
}
start(nconf.get('server'))