-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathdocapp.js
50 lines (41 loc) · 1.44 KB
/
docapp.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
const docapp = require('express')();
var swaggerJSDoc = require('swagger-jsdoc');
var swaggerUi = require('swagger-ui-express');
fs = require( 'fs' );
api_version = require('./package.json').version;
// Reference: Disable self signed certificates from browser
// https://stackoverflow.com/questions/7580508/getting-chrome-to-accept-self-signed-localhost-certificate
// https://stackoverflow.com/questions/20088/is-there-a-way-to-make-firefox-ignore-invalid-ssl-certificates
const cdir = process.env.CL_REST_STATE_DIR ? process.env.CL_REST_STATE_DIR : __dirname;
process.chdir(cdir);
var hostdef = 'localhost:' + config.PORT;
var swaggerDefinition = {
info: {
title: 'C-Lightning-REST',
version: api_version,
description: 'REST API suite for C-Lightning',
},
schemes: [config.PROTOCOL],
host: hostdef,
basePath: '/v1',
securityDefinitions: {
MacaroonAuth: {
type: 'apiKey',
name: 'macaroon',
in: 'header',
}
}
};
var options = {
swaggerDefinition,
apis: ['./controllers/*.js'],
};
const swaggerSpec = swaggerJSDoc(options);
docapp.get('/swagger.json', function(req, res) {
res.setHeader('Content-Type', 'application/json');
res.setHeader('Access-Control-Allow-Origin', config.PROTOCOL + '://' + hostdef);
res.send(swaggerSpec);
});
//Route for swagger documentation
docapp.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
module.exports = docapp;