-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (45 loc) · 1.53 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
require('dotenv').config()
const Hapi = require('@hapi/hapi');
const Mongoose = require('mongoose');
const { log } = require('./utils/utility-functions')
const MongoConnection = require('./utils/mongodb');
const Routes = require('./src/jobs/jobs.controller');
const Observer = require('./src/observer')
const Inert = require('@hapi/inert');
const Vision = require('@hapi/vision');
const HapiSwagger = require('hapi-swagger');
(async () => {
const db = MongoConnection.init();
const serverConnectionOptions = {
port: process.env.PORT,
host: process.env.HOST,
}
const server = new Hapi.Server(serverConnectionOptions);
server.route(Routes)
await server.register([
Inert,
Vision,
{
plugin: HapiSwagger,
options: {
info: {
title: 'Email Scheduler API Documentation',
version: '1.0',
},
}
}
]);
server.start();
server.events.on('start', () => {
log.info('Node server is running on ==> ', server.info.uri)
Observer();
});
server.events.on('stop', () => log.info('Server has been stopped'));
server.events.on('response', request => {
if (request.response) {
log.info(`${request.method.toUpperCase()} ${request.url.pathname} --> ${request.response.statusCode}`);
} else {
log.error('No statusCode : ', `${request.method.toUpperCase()} ${request.url.pathname} --> `);
}
});
})();