forked from hapi-swagger/hapi-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.js
More file actions
71 lines (61 loc) · 1.56 KB
/
debug.js
File metadata and controls
71 lines (61 loc) · 1.56 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
'use strict';
// `debug.js` - how to validate swagger output and get warning/error messages during development
const Hapi = require('hapi');
const Inert = require('inert');
const Vision = require('vision');
const Chalk = require('chalk');
const HapiSwagger = require('../');
const Pack = require('../package');
let Routes = require('./assets/routes-simple.js');
let server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 3000
});
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)}`);
}
};
server.on('log', formatLogEvent);
server.register(
[
Inert,
Vision,
{
register: HapiSwagger,
options: swaggerOptions
}
],
err => {
if (err) {
console.log(err);
}
server.route(Routes);
server.start(err => {
if (err) {
console.log(err);
} else {
console.log('Server running at:', server.info.uri);
}
});
}
);
// add templates only for testing custom.html
server.views({
path: 'bin',
engines: { html: require('handlebars') },
isCached: false
});