-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
66 lines (59 loc) · 1.41 KB
/
index.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict'
require('dotenv').config()
const glue = require('glue')
const debug = process.env.APP_DEBUG === 'true'
const manifest = {
server: {
host: process.env.APP_HOST || 'localhost',
port: process.env.APP_PORT || 8000,
router: { stripTrailingSlash: true },
routes: {
validate: {
failAction: async (request, h, err) => { throw err }
}
}
},
register: {
plugins: [
require('inert'),
require('vision'), {
plugin: require('hapi-swagger'),
options: {
securityDefinitions: {
jwt: {
type: 'apiKey',
name: 'Authorization',
in: 'header'
}
}
}
},
require('./app/jwt'), {
plugin: require('./app/auth'),
routes: { prefix: '/v1/auth' }
}, {
plugin: require('./app/user'),
routes: { prefix: '/v1/users' }
}, {
plugin: require('./app/todo'),
routes: { prefix: '/v1/todos' }
}
]
}
}
const routeTable = (server) => {
server.table()
.forEach((route) => console.log(`${route.method}\t${route.path}`))
}
const startServer = async () => {
try {
const server = await glue.compose(manifest)
await server.start()
console.log('Server running at: ', server.info.uri)
debug && routeTable(server)
} catch (error) {
console.error(error)
process.exit(1)
}
}
startServer()