-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
66 lines (60 loc) · 1.31 KB
/
app.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
const config = require('./config')
const Hapi = require('hapi')
const hapiRouter = require('hapi-router')
const Inert = require('inert')
const Vision = require('vision')
const HapiSwagger = require('hapi-swagger')
const Pack = require('./package')
// Create a server with a host and port
const server = Hapi.server({
host: config.HOST,
port: config.PORT,
routes: {
cors: {
origin: config.CORS
}
}
})
async function register () {
await server.register(require('./plugins'))
require('./auth')(server)
await server.register([
{
plugin: hapiRouter,
options: {
routes: './routes/*.js'
}
},
Inert,
Vision,
{
plugin: HapiSwagger,
options: {
schemes: [ process.env.NODE_ENV === 'production' ? 'https' : 'http' ],
host: config.CORLIEF_PATH,
cors: true,
info: {
title: `${Pack.name} API documentation`,
version: Pack.version
}
}
}
])
server.state("g_state", {
ignoreErrors: true
})
}
// Start the server
async function start () {
try {
config.validate()
await register()
await server.start()
} catch (err) {
console.error('error', err)
process.exit(1)
}
};
module.exports.start = start
module.exports.register = register
module.exports.server = server