-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprodServer.js
More file actions
49 lines (43 loc) · 1.29 KB
/
prodServer.js
File metadata and controls
49 lines (43 loc) · 1.29 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
import { extname, resolve } from 'path'
import Hapi from 'hapi'
import Inert from 'inert'
const server = new Hapi.Server()
server.connection({
host: 'localhost',
port: 3005,
})
server.register([Inert])
export function basicAuth(request, username, password, callback) {
// console.log(username, password)
if (username === 'delanylong' && password === 'textiles') {
return callback(null, true, { id: 'delanylong', name: 'delany and long' })
}
return callback(null, false, { id: 'anon', name: 'anonymous' })
}
export function staticFile({ basePath, pathname = '/index.html' }, reply) {
const filePath = basePath + pathname
return reply.file(filePath, { confine: false })
}
export function website({ info: { hostname, remotePort }, url }, reply) {
const location = { ...url, host: hostname }
const { pathname } = location
const basePath = resolve('build')
if (!extname(pathname)) return staticFile({ basePath }, reply)
return staticFile({ basePath, pathname }, reply)
}
// server.auth.strategy('simple', 'basic', {
// validateFunc: basicAuth,
// })
server.route({
method: 'GET',
path: '/{path*}',
config: {
// auth: 'simple',
handler: website,
},
})
// Start the server
server.start((err) => {
if (err) throw err
console.log('Server running at:', server.info.uri)
})