-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.js
More file actions
90 lines (79 loc) · 1.71 KB
/
app.js
File metadata and controls
90 lines (79 loc) · 1.71 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict';
const Hapi = require('@hapi/hapi');
const Inert = require('@hapi/inert');
const Vision = require('@hapi/vision');
const HapiSwagger = require('hapi-swagger');
const Pack = require('./package');
const init = async () => {
const port = process.env.PORT || 4000;
const server = Hapi.server({
port
});
const db = require('./config/database').db;
const swaggerOptions = {
info: {
title: 'Healert API Documentation',
version: Pack.version,
},
securityDefinitions: {
jwt: {
type: 'apiKey',
name: 'Authorization',
in: 'header'
}
},
};
await server.register([
Inert,
Vision,
{
plugin: HapiSwagger,
options: swaggerOptions
}
]);
// Load Hapi-Firebase Auth Strategy
const HapiFirebaseAuth = require('./plugins/firebase-auth');
// Register the plugin
await server.register({
plugin: HapiFirebaseAuth
});
const firebaseConfig = './config/service-account-file.json';
const admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.cert(firebaseConfig),
databaseURL: `https://${process.env.FIREBASE_DB || 'db'}.firebaseio.com`
});
// Include auth strategy
server.auth.strategy('firebase', 'firebase', {
instance: admin
});
await server.register({
plugin: require('hapi-router'),
options: {
routes: 'routes/**/*.js'
}
})
server.route({
method: 'GET',
path: '/',
handler: (request, h) => {
return {
status: 'ok',
message: 'Healert server is up and running'
};
}
});
server.route({
method: 'GET',
path: '/api',
handler: (request, h) => {
return {
status: 'ok',
message: 'Api Home'
};
}
});
await server.start();
console.log('Server running on %s', server.info.uri);
};
init();