swagger-api / swagger-api/swagger-ui

Swagger redirects to port 8080 when using BASE_URL

Open
#4,385 8 comments 18 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? 3
Which Swagger-UI version? 3.13.1/latest
How did you install Swagger-UI? With the docker image, behind an nginx reverse proxy
Which browser & version? Chrome, Safari...
Which operating system? MacOS X
Configuration (browser query string, constructor, config.yaml)

Docker-compose.yml

version: '3.5'

services:
  gateway:
    build: ./nginx
    ports:
      - "80:80"
      - "443:443"
    links:
      - swaggerui

  swaggerui:
    image: swaggerapi/swagger-ui
    restart: always
    environment:
      - BASE_URL=/swagger

nginx.conf

# Documentation server
server {
    listen 443 ;

    include /etc/nginx/proxy.conf;
    include /etc/nginx/ssl.conf;

    location ^~ /swagger {
        proxy_pass              http://swaggerui:8080;
    }
}
curl -v http://doc.dev/swagger

*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to doc.dev (127.0.0.1) port 80 (#0)
* Server auth using Basic with user 'test'
> GET /swagger HTTP/1.1
> Host: doc.dev
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Server: nginx
< Date: Wed, 28 Mar 2018 10:50:30 GMT
< Content-Type: text/html
< Content-Length: 185
< Connection: keep-alive
< Location: http://doc.dev:8080/swagger/
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, OPTIONS
< Access-Control-Allow-Headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type
<
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.10.3</center>
</body>
</html>
* Connection #0 to host doc.dev left intact

BUT when I add a final slash

curl -v http://doc.dev/swagger/
# I get the swagger app
Expected Behavior

It should work for http://doc.dev/swagger and http://doc.dev/swagger/ (with final slash) as well

Current Behavior

When not adding a final slash, we are redirected to 8080

Context

I have to explain this strange behavior to my teammates and to take care of the links I send.

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 docker-compose.yml and nginx.conf, then reproduce the redirect with curl against /swagger and /swagger/. Check how the nginx reverse proxy and Swagger UI BASE_URL handle the missing trailing slash. Done means both URLs reach the Swagger app without redirecting to port 8080.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.