forked from hapi-swagger/hapi-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom.js
More file actions
121 lines (111 loc) · 2.69 KB
/
Copy pathcustom.js
File metadata and controls
121 lines (111 loc) · 2.69 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
'use strict';
// `custom.js` - how build a custom documentation page with its own CSS and JS
const Blipp = require('blipp');
const Hapi = require('hapi');
const Inert = require('inert');
const Vision = require('vision');
const HapiSwagger = require('../');
const Pack = require('../package');
let Routes = require('./assets/routes-simple');
const goodOptions = {
ops: {
interval: 1000
},
reporters: {
console: [
{
module: 'good-squeeze',
name: 'Squeeze',
args: [
{
log: '*',
response: '*'
}
]
},
{
module: 'good-console'
},
'stdout'
]
}
};
let server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 3000
});
let swaggerOptions = {
documentationPage: false,
swaggerUIPath: '/ui/',
basePath: '/v1/',
pathPrefixSize: 2,
info: {
title: 'Test API Documentation',
description: 'This is a sample example of API documentation.',
version: Pack.version,
termsOfService: 'https://github.com/glennjones/hapi-swagger/',
contact: {
email: 'glennjonesnet@gmail.com'
},
license: {
name: 'MIT',
url:
'https://raw.githubusercontent.com/glennjones/hapi-swagger/master/license.txt'
}
},
tags: [
{
name: 'sum',
description: 'working with maths',
externalDocs: {
description: 'Find out more',
url: 'http://example.org'
}
},
{
name: 'store',
description: 'storing data',
externalDocs: {
description: 'Find out more',
url: 'http://example.org'
}
}
],
jsonEditor: true,
validatorUrl: null
};
server.register(
[
Inert,
Vision,
Blipp,
{
register: require('good'),
options: goodOptions
},
{
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: 'examples/assets',
engines: { html: require('handlebars') },
isCached: false
});