Remove preMiddleware.
Not necessary since this can easily be done with an app.use() before calling loopback-explorer.
This commit is contained in:
parent
34b3983b9d
commit
6224243791
13
README.md
13
README.md
|
@ -30,12 +30,10 @@ Many aspects of the explorer are configurable.
|
|||
See [options](#options) for a description of these options:
|
||||
|
||||
```js
|
||||
// Mount middleware before calling `explorer()` to add custom headers, auth, etc.
|
||||
app.use('/explorer', loopback.basicAuth('user', 'password'));
|
||||
app.use('/explorer', explorer(app, {
|
||||
basePath: '/custom-api-root',
|
||||
preMiddleware: [
|
||||
// You can add as many items to this middleware chain as you like
|
||||
loopback.basicAuth(bitmex.settings.basicAuth.user, bitmex.settings.basicAuth.password)
|
||||
],
|
||||
swaggerDistRoot: '/swagger',
|
||||
apiInfo: {
|
||||
'title': 'My API',
|
||||
|
@ -59,7 +57,6 @@ Options are passed to `explorer(app, options)`.
|
|||
> to a path different than '/api', e.g. with
|
||||
> `loopback.use('/custom-api-root', loopback.rest());
|
||||
|
||||
|
||||
`swaggerDistRoot`: **String**
|
||||
|
||||
> Sets a path within your application for overriding Swagger UI files.
|
||||
|
@ -89,9 +86,3 @@ Options are passed to `explorer(app, options)`.
|
|||
> Default: Read from package.json
|
||||
|
||||
> Sets your API version. If not present, will read from your app's package.json.
|
||||
|
||||
`preMiddleware`: **Array<Function>|Function**
|
||||
|
||||
> Middleware to run before any explorer routes, including static routes.
|
||||
|
||||
> Useful for setting HTTP Auth, modifying the `Host` header, and so on.
|
||||
|
|
10
index.js
10
index.js
|
@ -23,21 +23,13 @@ module.exports = explorer;
|
|||
function explorer(loopbackApplication, options) {
|
||||
options = _defaults({}, options, {
|
||||
resourcePath: 'resources',
|
||||
apiInfo: loopbackApplication.get('apiInfo') || {},
|
||||
preMiddleware: []
|
||||
apiInfo: loopbackApplication.get('apiInfo') || {}
|
||||
});
|
||||
|
||||
var app = express();
|
||||
|
||||
swagger(loopbackApplication, app, options);
|
||||
|
||||
// Allow the user to attach middleware that will run before any
|
||||
// explorer routes, e.g. for access control.
|
||||
if (typeof options.preMiddleware === 'function' ||
|
||||
(Array.isArray(options.preMiddleware) && options.preMiddleware.length)) {
|
||||
app.use(options.preMiddleware);
|
||||
}
|
||||
|
||||
app.disable('x-powered-by');
|
||||
|
||||
// config.json is loaded by swagger-ui. The server should respond
|
||||
|
|
Loading…
Reference in New Issue