swagger-api / swagger-api/swagger-ui

Unable to load static UI files

Open
#6,247 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

cat: docker type: question type: support
Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q&A (please complete the following information)
  • OS: 5.7.9-1-MANJARO
  • Browser: firefox
  • Version: 78
  • Method of installation: docker
  • Swagger-UI version: 3.30.0
  • Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration

Running docker-compose with swagger and nginx, consider the following docker-compose.yml:

version: '3'

services:
  swagger:
    image: swaggerapi/swagger-ui:v3.30.0
    ...
  nginx:
    image: nginx:mainline-alpine
    depends_on:
      - swagger
    ports:
      - 80:80
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf

and the following nginx.conf:

http {
  server {
    listen 80 default_server;
    server_name _;
    location /swagger {
      proxy_pass http://swagger:8080/;
    }
  }
}
Describe the bug you're encountering

When going to http://localhost the html loads fine however the static assets linked from the html don't seem to load. When looking in the network inspector I noticed that the assets are loaded from localhost/<FILE_NAME> instead of localhost/docs/<FILE_NAME>.

One of the outgoing requests to an asset:

GET /swagger-ui.css HTTP/1.1
Host: localhost
User-Agent: Mozilla [REDACTED]
Accept: text/css,*/*;q=0.1
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Referer: http://localhost/swagger
Cache-Control: max-age=0

and the response:

HTTP/1.1 404 Not Found
Server: nginx
Date: Tue, 21 Jul 2020 07:45:18 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 2439
Connection: keep-alive
Cache-Control: no-store, must-revalidate
ETag: "987-pkNlMUTYJp6pkXv/jlWCJfwNiNM"
To reproduce...

Steps to reproduce the behavior:

  1. Create a local directory with the files described in Content & configuration.
  2. Run docker-compose up.
  3. Go to http://localhost/docs
  4. Confirm that static assets are not being loaded.
Expected behavior

The files are referred from the base URL and thus properly loaded.

Additional context or thoughts

I also tried to set the BASE_URL environmental variable to /swagger and changed the nginx proxy_pass to http://swagger:8080/docs/ however it yielded the same result.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the nginx.conf and docker-compose.yml configuration shown in the issue, then reproduce the missing static assets through the /swagger path. Trace how Swagger UI generates its asset URLs and compare them with the proxy path. Done means the HTML and static files load correctly when accessed through the configured path.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, javascript, nginx
Domain
devops, frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.