Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply openapi_prefix to redirect URL #1159

Closed
wants to merge 12 commits into from
Closed

Conversation

nunomen
Copy link

@nunomen nunomen commented Mar 24, 2020

For my application I need to use Apache as a Reverse Proxy, like this:

<VirtualHost *:80>
    ServerName ${SERVER_NAME}
    DocumentRoot ${SERVER_DOCUMENT_ROOT}
    ##  Other Redirects
    
    ## FastApi App
    Redirect permanent /app    ${SERVER_NAME}:/app
</VirtualHost>

<VirtualHost *:443>
    ProxyPass         "/app" "http://localhost:57012"
    ProxyPassReverse  "/app" "http://localhost:57012"

In order to do this, I have to setup the fastapi app with the following settings:

app = FastAPI(
    title="app",
    description="Ipsum Lorem",
    openapi_prefix="/app",
    swagger_ui_init_oauth={"clientId": "app-id",},
)

The openapi_prefix is needed to set up the application behind a reverse proxy as carefully explained in FastApi documentation, otherwise openapi.json is not served in the right place. But, for some reason this openapi_prefix was not being applied on the oauth2 redirect_uri in the swagger html generator.

@nunomen
Copy link
Author

nunomen commented Mar 25, 2020

Travis build was failing because of this:

fastapi/applications.py:116: error: Unsupported operand types for + ("str" and "None")
fastapi/applications.py:116: note: Right operand is of type "Optional[str]"

I don't really understand how these type checkers work, but it doesn't seem to me that Optional[str] is the appropriate choice, given that swagger_ui_oauth2_redirect_url is never None and has a default value of type str.

@nunomen nunomen changed the title Apply openapi prefix to redirect URL Mar 25, 2020
@nunomen
Copy link
Author

nunomen commented Mar 26, 2020

Build is still failing and I'm trying to find what is wrong since the 3 first builds don't explicitly say which error was raised.

@codecov
Copy link

codecov bot commented Mar 27, 2020

Codecov Report

Merging #1159 into master will not change coverage by %.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##            master     #1159     +/-   ##
===========================================
  Coverage   100.00%   100.00%             
===========================================
  Files          331       223    -108     
  Lines         8085      6668   -1417     
===========================================
- Hits          8085      6668   -1417     
Impacted Files Coverage Δ
fastapi/applications.py 100.00% <100.00%> (ø)
fastapi/utils.py 100.00% <0.00%> (ø)
fastapi/routing.py 100.00% <0.00%> (ø)
docs/src/app_testing/tutorial002.py
docs/src/security/tutorial005.py
docs/src/additional_responses/tutorial001.py
docs/src/dependencies/tutorial006.py
docs/src/custom_request_and_route/tutorial003.py
docs/src/sql_databases/sql_app/crud.py
docs/src/custom_request_and_route/tutorial002.py
... and 105 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update faf88ce...0270abf. Read the comment docs.

@nunomen
Copy link
Author

nunomen commented Apr 1, 2020

Duplicate of #1199

@nunomen nunomen closed this Apr 1, 2020
@tiangolo
Copy link
Owner

Thanks for your work @littlebrat ! Clever implementation. But yeah, with #1199 we can handle the issue from the "root" 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants