forked from hapi-swagger/hapi-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.js
70 lines (59 loc) · 1.5 KB
/
debug.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
67
68
69
70
// `debug.js` - how to validate swagger output and get warning/error messages during development
const Blipp = require('blipp');
const Hapi = require('@hapi/hapi');
const Inert = require('@hapi/inert');
const Vision = require('@hapi/vision');
const Chalk = require('chalk');
const HapiSwagger = require('../');
const Pack = require('../package');
let Routes = require('./assets/routes-simple.js');
let swaggerOptions = {
basePath: '/v1',
pathPrefixSize: 2,
info: {
title: 'Test API Documentation',
version: Pack.version
},
debug: true // switch on debug
};
// use chalk to log colour hapi-swagger messages to console.
const formatLogEvent = function(event) {
if (event.tags.error) {
console.log(`[${event.tags}], ${Chalk.red(event.data)}`);
} else {
console.log(`[${event.tags}], ${Chalk.green(event.data)}`);
}
};
const ser = async () => {
const server = Hapi.Server({
host: 'localhost',
port: 3000
});
// Blipp and Good - Needs updating for Hapi v17.x
await server.register([
Inert,
Vision,
Blipp,
{
plugin: HapiSwagger,
options: swaggerOptions
}
]);
server.route(Routes);
server.views({
path: 'examples/assets',
engines: { html: require('handlebars') },
isCached: false
});
await server.start();
server.events.on('log', formatLogEvent);
return server;
};
ser()
.then(server => {
console.log(`Server listening on ${server.info.uri}`);
})
.catch(err => {
console.error(err);
process.exit(1);
});