How to disable API explorer page ?
I do as the document say but it not work
here is my config
const config = {
rest: {
port: +(process.env.PORT || 3000),
host: process.env.HOST,
openApiSpec: {
setServersFromRequest: true,
disabled: true
},
apiExplorer: {
disabled: true
}
}
};
openApiSpec can't access but API explorer can access.
rest.apiExplorer.disabled only disables redirect to an externally-hosted Swagger UI instance.
To disable the self-hosted instance, reverse the steps to add self-hosted apiExplorer.
In application.ts, add useSelfHostedSpec: false to RestExplorerBindings.CONFIG. For example:
this.bind(RestExplorerBindings.CONFIG).to({
path: '/explorer',
useSelfHostedSpec: false
});
Thanks @shadyanwar for the alternate solution. To avoid confusion, as per-docs, useSelfHostedSpec does remove the explorer's self-hosting of openapi.json for it's own use. This however does not fully remove the explorer.
@achrinza I assumed the aim of the question was to disable access to the explorer. Is it still accessible in any way after setting useSelfHostedSpec to false?
@shadyanwar I've just tested this to be sure, the explorer is still accessible at /explorer. useSelfHostedSpec: false removed /explorer/openapi.json but not the explorer itself. However, this may differ if the self-hosted explorer is behind a proxy as per-docs.
For completeness, to entirely disable explorer make both changes below:
./index.js - Add the following setting to options. [disable remote fallback]
js
const config = {
rest: {
// ...
apiExplorer: {
disabled: true,
},
},
};
./src/application.ts - Remove/comment the following code [remove self hosted component]
ts
// Customize @loopback/rest-explorer configuration here
this.bind(RestExplorerBindings.CONFIG).to({
path: '/explorer',
});
this.component(RestExplorerComponent);
@dougal83 thank you for sharing the instructions. Would you like to contribute them to our documentation? Few places where they may fit:
Most helpful comment
For completeness, to entirely disable explorer make both changes below:
./index.js- Add the following setting to options. [disable remote fallback]js const config = { rest: { // ... apiExplorer: { disabled: true, }, }, };./src/application.ts- Remove/comment the following code [remove self hosted component]ts // Customize @loopback/rest-explorer configuration here this.bind(RestExplorerBindings.CONFIG).to({ path: '/explorer', }); this.component(RestExplorerComponent);