delete
delete

Reputation: 19148

How to install LoopBack-API-Explorer into existing application

I'm following the official "Getting Started"-tutorial of LoopBack: https://loopback.io/doc/en/lb3/Use-API-Explorer.html

Everything works fine apparently. However, when it comes to open the API-Explorer in a webbrowser, it gives 404:

404 Cannot GET /explorer

This is working as expected: http://0.0.0.0:3000/

This returns 404 status code: http://0.0.0.0:3000/explorer

Is it lack of documentation or some incampatibilities between Tutorial and newest loopback-generator?

I did every step exactly as mentioned in the tutorial.

Maybe this config-file called "server/config.json" can help, because i stumbled upon a setting "legacyExplorer":false.

Or is it necessary to install the explorer as a separated component?

{
  "restApiRoot": "/api",
  "host": "0.0.0.0",
  "port": 3000,
  "remoting": {
    "context": false,
    "rest": {
      "normalizeHttpPath": false,
      "xml": false
    },
    "json": {
      "strict": false,
      "limit": "100kb"
    },
    "urlencoded": {
      "extended": true,
      "limit": "100kb"
    },
    "cors": false,
    "handleErrors": false
  },
  "legacyExplorer": false
}

Upvotes: 2

Views: 756

Answers (1)

itinance
itinance

Reputation: 12398

The tutorial comes with two different cli-tools for creating the application stack: apic and slc.

I bet that you were using apic and I'm pretty sure that this tutorial would work out of the box if you would use slc to create all these boilerplate instead of apic.

To make it run in your apic-based setup, just install the api-explorer.

npm install --save loopback-component-explorer --save

and register the route as follows:

In the directory-structure from root-folder there is a folder called "server". Create an empty file named "component-config.json" into the "server" folder and place the following code inside:

{
  "loopback-component-explorer": {
    "mountPath": "/explorer"
  }
}

Now you should be able to open the explorer-page with the url http://0.0.0.0:3000/explorer.

Upvotes: 8

Related Questions