parent
fabc7cf5fb
commit
d736de2a39
38
index.js
38
index.js
|
@ -1,18 +1,18 @@
|
|||
'use strict';
|
||||
'use strict';
|
||||
/*!
|
||||
* Adds dynamically-updated docs as /explorer
|
||||
*/
|
||||
var url = require('url');
|
||||
var path = require('path');
|
||||
var urlJoin = require('./lib/url-join');
|
||||
var _defaults = require('lodash').defaults;
|
||||
var cors = require('cors');
|
||||
var createSwaggerObject = require('loopback-swagger').generateSwaggerSpec;
|
||||
var SWAGGER_UI_ROOT = require('strong-swagger-ui/index').dist;
|
||||
var STATIC_ROOT = path.join(__dirname, 'public');
|
||||
var url = require('url');
|
||||
var path = require('path');
|
||||
var urlJoin = require('./lib/url-join');
|
||||
var _defaults = require('lodash').defaults;
|
||||
var cors = require('cors');
|
||||
var createSwaggerObject = require('loopback-swagger').generateSwaggerSpec;
|
||||
var SWAGGER_UI_ROOT = require('strong-swagger-ui/index').dist;
|
||||
var STATIC_ROOT = path.join(__dirname, 'public');
|
||||
|
||||
module.exports = explorer;
|
||||
explorer.routes = routes;
|
||||
module.exports = explorer;
|
||||
explorer.routes = routes;
|
||||
|
||||
/**
|
||||
* Example usage:
|
||||
|
@ -21,13 +21,13 @@
|
|||
* explorer(app, options);
|
||||
*/
|
||||
|
||||
function explorer(loopbackApplication, options) {
|
||||
function explorer(loopbackApplication, options) {
|
||||
options = _defaults({}, options, { mountPath: '/explorer' });
|
||||
loopbackApplication.use(options.mountPath, routes(loopbackApplication, options));
|
||||
loopbackApplication.set('loopback-component-explorer', options);
|
||||
}
|
||||
}
|
||||
|
||||
function routes(loopbackApplication, options) {
|
||||
function routes(loopbackApplication, options) {
|
||||
var loopback = loopbackApplication.loopback;
|
||||
var loopbackMajor = loopback && loopback.version &&
|
||||
loopback.version.split('.')[0] || 1;
|
||||
|
@ -84,7 +84,7 @@
|
|||
}
|
||||
|
||||
return router;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup Swagger documentation on the given express app.
|
||||
|
@ -95,7 +95,7 @@
|
|||
* swagger documentation.
|
||||
* @param {Object} opts Options.
|
||||
*/
|
||||
function mountSwagger(loopbackApplication, swaggerApp, opts) {
|
||||
function mountSwagger(loopbackApplication, swaggerApp, opts) {
|
||||
var swaggerObject = createSwaggerObject(loopbackApplication, opts);
|
||||
|
||||
// listening to modelRemoted event for updating the swaggerObject
|
||||
|
@ -113,12 +113,12 @@
|
|||
swaggerApp.get(resourcePath, function sendSwaggerObject(req, res) {
|
||||
res.status(200).send(swaggerObject);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function setupCors(swaggerApp, remotes) {
|
||||
function setupCors(swaggerApp, remotes) {
|
||||
var corsOptions = remotes.options && remotes.options.cors ||
|
||||
{ origin: true, credentials: true };
|
||||
|
||||
// TODO(bajtos) Skip CORS when remotes.options.cors === false
|
||||
swaggerApp.use(cors(corsOptions));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue