-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.js
More file actions
48 lines (43 loc) · 1.07 KB
/
server.js
File metadata and controls
48 lines (43 loc) · 1.07 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
require('dotenv').config()
const log = console.log
const Boom = require('boom')
const Hapi = require('hapi')
const HapiJWT = require('hapi-auth-jwt2')
const chalk = require('chalk')
const Inert = require('inert')
const Vision = require('vision')
const category = require('./routes/category')
const certification = require('./routes/certification')
const user = require('./routes/user')
const approver = require('./routes/approver')
const routes = [category, certification, user, approver]
const plugins = [HapiJWT, Inert, Vision, ...routes]
const server = Hapi.server({
host: process.env.HOST || '127.0.0.1',
port: process.env.PORT || 8000,
routes: {
cors: {
credentials: false
}
}
})
async function start() {
try {
await server.register(plugins, {
routes: {
prefix: '/api'
}
})
await server.start()
log(
'Hapi server running at :',
chalk.yellow(server.info.uri),
`[${chalk.cyan(process.env.ENVIRONMENT)}]`
)
} catch (err) {
log(err)
process.exit(1)
return Boom.badImplementation()
}
}
start()