Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Modify the StrongLoop's LoopBack Explorer CSS

We're using Strongloop's LoopBack for our REST APIs and would like to modify the CSS for the LoopBack Explorer. However, it's not clear which CSS files are being used (LoopBack vs Swagger) and where they're located. I was not able to find specific documentation for this.

like image 492
A2MetalCore Avatar asked Jan 21 '15 17:01

A2MetalCore


2 Answers

You can modify more than just the css. And also, if you generate your Loopback application using slc loopback like I did, you'll find that your server/server.js doesn't look immediately in a way you can configure it like it's shown in the accepted answer.

Instead you can use server/component-config.json to instruct the loopback component explorer to use an alternative directory for static files for the swagger-ui. With the uiDirs configuration below I configured it to go look for static files in the server/explorer directory.

{
  "loopback-component-explorer": {
    "mountPath": "/explorer",
    "uiDirs": "server/explorer",
    "apiInfo": {
      "title": "My API",
      "description": "Description of my API"
    }
  }
}

* When using IISNode uiDirs has to be set to "explorer" otherwise it's "server/explorer" as per @phegde 's comment

In my server directory I created a index.html which is a copy from node_modules/loopback-component-explorer/public/index.html and also I created an images folder with a custom logo.

enter image description here

And finally, If you want to have custom css, copy node_modules/loopback-component-explorer/public/css/loopbackStyles.css into server/explorer/css/loopbackStyles.css

like image 185
Christiaan Westerbeek Avatar answered Nov 15 '22 20:11

Christiaan Westerbeek


You can provide your own version of Swagger UI files via options.uiDirs.

  1. Edit your server/server.js and add this config option to the explorer:

    app.use(explorer(app, { uiDirs: path.resolve(__dirname, 'explorer') }));
    
  2. Copy the directory node_modules/loopback-explorer/public/css to server/explorer/css

  3. Customize the copied CSS files as you need.

You should lock loopback-explorer's major & minor version in your package.json. Newer versions of loopback-explorer may change the CSS in which case your customization may stop working.

like image 28
Miroslav Bajtoš Avatar answered Nov 15 '22 21:11

Miroslav Bajtoš