Remove preMiddleware.

Not necessary since this can easily be done with an app.use() before
calling loopback-explorer.
This commit is contained in:
Samuel Reed 2014-07-10 14:16:10 -05:00
parent 34b3983b9d
commit 6224243791
2 changed files with 3 additions and 20 deletions

View File

@ -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.

View File

@ -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