-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (54 loc) · 1.36 KB
/
Copy pathindex.js
File metadata and controls
63 lines (54 loc) · 1.36 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
const Hapi = require('@hapi/hapi')
require('dotenv').config()
const db = require('./server/dbConfig')
const config = require('config')
const Path = require('path')
const server = Hapi.server({
port: process.env.PORT || config.get('Customer.server.port'),
host: config.get('Customer.server.host'),
routes: {
files: {
relativeTo: Path.join(__dirname, 'client', 'build')
}
}
})
server.route(require('./server/routes/auth.routes'))
server.route(require('./server/routes/board.routes'))
server.route(require('./server/routes/list.routes'))
server.route(require('./server/routes/item.routes'))
const init = async () => {
try {
await db.connect()
await server.register(require('inert'))
if (process.env.NODE_ENV === 'production') {
server.route({
method: 'GET',
path: '/static/{param*}',
handler: {
directory: {
path: './static',
index: ['index.html', 'default.html']
}
}
})
server.route({
method: 'GET',
path: '/{param*}',
handler: {
file: {
path: "./index.html"
}
}
})
}
await server.start()
console.log('Server running on %s', server.info.uri)
} catch(err) {
throw err
}
}
process.on('unhandledRejection', (err) => {
console.log(err)
process.exit(1)
})
init()