Skip to content

Commit

Permalink
Merge pull request #83 from huge-success/redirect_to_slash_fix
Browse files Browse the repository at this point in the history
redirect for non slash route to fix relative links in index.html
  • Loading branch information
ahopkins committed Apr 7, 2019
2 parents b202af2 + e6a6013 commit 3b3410d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -22,7 +22,7 @@ from sanic_openapi import swagger_blueprint
app.blueprint(swagger_blueprint)
```

You'll now have a Swagger UI at the URL `/swagger` and an OpenAPI 2.0 spec at `/swagger/swagger.json`.
You'll now have a Swagger UI at the URL `/swagger/` and an OpenAPI 2.0 spec at `/swagger/swagger.json`.
Your routes will be automatically categorized by their blueprints.

## Example
Expand Down
11 changes: 9 additions & 2 deletions sanic_openapi/swagger.py
Expand Up @@ -3,7 +3,7 @@
import os

from sanic.blueprints import Blueprint
from sanic.response import json
from sanic.response import json, redirect
from sanic.views import CompositionView

from .doc import route_specs, RouteSpec, serialize_schema, definitions
Expand All @@ -14,7 +14,14 @@
dir_path = os.path.dirname(os.path.realpath(__file__))
dir_path = os.path.abspath(dir_path + '/ui')

blueprint.static('/', dir_path + '/index.html')

# Redirect "/swagger" to "/swagger/"
@blueprint.route('', strict_slashes=True)
def index(request):
return redirect("{}/".format(blueprint.url_prefix))


blueprint.static('/', dir_path + '/index.html', strict_slashes=True)
blueprint.static('/', dir_path)


Expand Down

0 comments on commit 3b3410d

Please sign in to comment.