Tips for Customizing the StrongLoop LoopBack Explorer CSS

Our team is currently utilizing Strongloop's LoopBack framework for our REST APIs and we are looking to customize the CSS of the LoopBack Explorer. Unfortunately, it seems unclear which CSS files are being employed (LoopBack vs Swagger) and their exact location. I have been unable to locate any specific documentation regarding this issue.

Answer №1

There are more changes you can make beyond just adjusting the css. If you create your Loopback application using slc loopback as I did, you'll notice that the server/server.js file does not initially appear in a configurable format like it is shown in the accepted answer.

Instead, you can utilize the server/component-config.json file to direct the loopback component explorer to use a different directory for static files for the swagger-ui. By setting the uiDirs configuration as shown below, I directed it to search 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"
    }
  }
}

* If using IISNode, set uiDirs to "explorer"; otherwise, it should be "server/explorer" as per @phegde 's comment

I created an index.html in my server directory by copying from

node_modules/loopback-component-explorer/public/index.html
, and also added an images folder with a personalized logo.

https://i.stack.imgur.com/IENrd.png

Lastly, to apply custom css, duplicate the

node_modules/loopback-component-explorer/public/css/loopbackStyles.css
into
server/explorer/css/loopbackStyles.css

Answer №2

If you want to customize Swagger UI files, you can do so by using the options.uiDirs parameter.

  1. To begin, open your server/server.js file and include the following configuration option:

    app.use(explorer(app, { uiDirs: path.resolve(__dirname, 'explorer') }));
    
  2. Next, copy the contents of

    node_modules/loopback-explorer/public/css
    to server/explorer/css

  3. Feel free to make any necessary modifications to the copied CSS files.

Remember to specify the specific version of loopback-explorer in your package.json file to prevent any unexpected changes that might affect your customizations when a newer version is released.

Answer №3

In case you forgot to lock the loopback-explorer in package.json or if you began running your application from the latest release of loopback(v2.x), you'll need to make an additional adjustment:

  1. If you used the generator tool to create your loopback app, modify server/component-config.json as follows:

    { "loopback-component-explorer": null }

2.Transfer the folder

node_modules/loopback-explorer/public/
to server/explorer/ per Miroslav's recommendation. If you choose to copy the entire directory, you can also update the index.html file.

  1. Edit the server/server.js file and include this line:
    app.use('/explorer',explorer.routes(app, { uiDirs: path.resolve(__dirname, 'explorer') }));
    Also, ensure to import the explorer module at the beginning of the file:
    var explorer = require('loopback-component-explorer');

4.Personalize the user interface of your explorer, with all the required files located in server/explorer

Answer №4

When using the loopback-component-explorer, it is important to ensure that the uiDirs specified in the component-config.json are configured correctly. I encountered a similar issue and resolved it by adding the following line:

"uiDirs": ["server/explorer"]

instead of

"uiDirs": "server/api-explorer",

Answer №5

I have successfully applied custom CSS styles to the Loopback API Explorer header.

Here are the steps I took:

  1. Navigate to node_modules > loopback-component-explorer > public > css folder
  2. Copy the file named loopbackStyles.css
  3. Create a new folder called explorer under the server directory
  4. Create a css folder within the explorer folder and paste the loopbackStyles.css file inside
  5. Add the configuration below to the component-config.json file
{
  "loopback-component-explorer": {
    "mountPath": "/explorer",
    "generateOperationScopedModels": true,
    "uiDirs": "server/explorer"
  }
}

To modify the color of the Loopback header, I simply changed the background-color property in the body #header CSS selector in the loopbackStyles.css file.

To replace the default logo name in the header with a custom name, I added the following CSS styles to loopbackStyles.css:

.swagger-ui-wrap #logo{
  display: none;
}
.swagger-ui-wrap:after { 
  content: "MyOwn API Explorer";
  color: #fff;
  font-weight: bold; 
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The curious conduct of wild safari creatures

I have been using JavaScript to split my ePub chapter into pages by wrapping the code with new divs that represent separate pages. I have also created CSS styles for these new divs. Everything works perfectly when the file has a filename extension of &apos ...

Browser resize affects the overlap of DIVs

I've seen similar posts before, but I believe the issue with my website (***) is unique. At full size, the website looks exactly how I want it to. However, when I resize the browser window, the text ("ABOUT INTERNATIONAL PARK OF COMMERCE.." and below ...

Adaptable Bootstrap navigation bar

In the process of creating a responsive menu, I have designed a navbar for desktop that includes 3 text links and 3 small pictures that are also links. However, when transitioning to a smaller screen size, my goal is to keep the 3 small pictures as they a ...

The jQuery onClick function functions effectively for the initial two clicks; however, it ceases to

I am currently experimenting with jQuery to dynamically load a specific div from another page on my server into a designated section on the existing page. While the code is successfully functioning for the first two clicks on the website, it fails to work ...

Guide on how to modify the CSS styling of a particular <td> element when its parent contains a specific class

.webgrid-table td, th { border: 1px solid #98bf21; padding: 3px 7px 2px; } I am facing an issue where the style defined above is being applied to all td elements. However, I want to exclude the styling for a td that is within a tr element with the ...

CSS hover effects are not displayed when using the input type button

I'm having issues with my hover effects not showing: <input type="button" class="button" value="Click"> However, this code works fine: <button class="button">Click</button> The CSS codes are ...

poor scrolling performance when transitioning focus between elements in the interface

Looking for some assistance? Check out this codepen. I'm currently working on a search bar widget that allows navigation from the input field to the search results, displayed as a series of divs. The navigation is controlled via jquery, where the foc ...

Reduce the size of a webpage by 10%

Have you ever noticed that when you press Ctrl+- on any browser, the page scales down to 90% of its original size? It actually looks nicer at 90%, so I want my webpage to default to opening at 90% instead of 100%. I've tried following common approach ...

Using JavaScript or JQuery, move an image from one location to another by removing it and adding

Firstly, feel free to check out the JSFiddle example My task involves moving an image with the class "Full" after a div with the class "group-of-buttons" using JavaScript. Here is the snippet of HTML code: <img src="http://i.telegraph.co.uk/multimedia ...

Move divs that are currently not visible on the screen to a new position using CSS animations

Upon entering the site, I would like certain divs to animate from an offscreen position. I came across this code snippet: $( document ).ready(function() { $('.box-wrapper').each(function(index, element) { setTimeout(function(){ ...

I am experiencing an issue with Safari where there is an unexpected rounded border appearing that

Upon inspecting the image, a slight border is visible behind the main border on Chrome and Firefox. However, Safari and iPhone display a rounded thin border instead. Can you help us understand why this discrepancy is happening and how we can remove it? P ...

How to incorporate Django syntax into CSS styling

Imagine a scenario where a Django site is equipped with numerous stylesheets. CSS and JS files are located in the static/ directory within an app's folder or in the global site directory. Various color themes are employed across different pages, neces ...

Tips for correctly positioning CSS elements:

I am currently working on a slider using noUi Slider and aiming for an elegant solution. To accommodate the large size of the handle, I expanded the base UI with extra values which are not allowed, causing the handle to jump back to the permitted values. T ...

Incorporating Image Caching Optimizations in CSS

My current dilemma I currently implement Cache Busting for my CSS files like this: echo "&lt;link href='stylesheet.css?" . filemtime('stylesheet.css') . "' />" My objective Now I want to achieve a similar approach for th ...

Ways to disable the caching feature in Google Chrome

When I am working on CSS and JS around a page, I need to disable the cache mechanism in Google Chrome browser. A trick is to open Chrome DevTools, which automatically disables the cache mechanism (you can configure this in the settings section). Are ther ...

CSS media query to center the logo on mobile screens

As someone new to CSS and media queries, I'm reaching out for help from the experts. My challenge involves positioning a mat-toolbar with a menu button and app logo. The HTML code in question is as follows: <div class="toolbar"> <mat-too ...

Troubleshooting HTML Output Display Issues

I've been trying to post my content exactly as I submit it, but for some reason, it's not working. When I enter two paragraphs in a post, the output doesn't maintain that formatting. Instead, it removes the paragraph breaks and displays the ...

Tips for dynamically resizing the content area using CSS without the need for javascript

What I need is as follows: The blue area should resize when the browser window resizes. The header must be visible at all times. The blue area should start right after the header ends, not overlapping or appearing above it. The blue area should end befor ...

Background of jQuery-UI Slider

Can the background color of a jQuery-UI Slider widget be set using JavaScript? This is the default setting: What I am trying to accomplish is the following: The green range should be determined based on historical data. I want to visually show the user ...

Creating a centered floating card within a div that shrinks to fit its contents: A CSS how-to guide

I am facing a challenge with positioning a floating card that needs to be centered over the parent div (which happens to be selectable because it's a map). So far, I have only managed to achieve this by setting a fixed width for the card using the fo ...