Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: Add ProxyFix to serve swagger.json over HTTPs
  • Loading branch information
Angeluz-07 committed Apr 21, 2020
commit d315d5bded6b39b72468bcaa8500323f89e8ebbe
8 changes: 8 additions & 0 deletions time_tracker_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def init_app(app: Flask):
app.logger.setLevel(logging.INFO)
add_debug_toolbar(app)

add_werkzeug_proxy_fix(app)

cors_origins = app.config.get('CORS_ORIGINS')
if cors_origins:
enable_cors(app, cors_origins)
Expand Down Expand Up @@ -74,3 +76,9 @@ def enable_cors(app: Flask, cors_origins: str):
cors_origins_list = cors_origins.split(",")
CORS(app, resources={r"/*": {"origins": cors_origins_list}})
app.logger.info("Set CORS access to [%s]" % cors_origins)


def add_werkzeug_proxy_fix(app: Flask):
from werkzeug.middleware.proxy_fix import ProxyFix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call this function add_fixers and in the commit then I would say

Add ProxyFix to serve swagger over HTTPs.

This is supposed to be registered in the CHANGELOG and provide this node.
You can leave the logged message because it serves to explain what this particular fix is for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the commit message change. But I don't agree with the function name "add_fixers". It seems to general for me. This is a fix for a very specific problem. If later we found we need more fixers, it'll be ok to change the name to "add_fixers". But for now I think we are ok leaving the name of the function specific.

Copy link
Contributor

@EliuX EliuX Apr 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but that function explains reasons and not what that actual function does. If you want to explain the reasons in a verbose way, better use a logger. But I understand your point on trying to be more specific, so I would name for instance use_werkzeug_proxy_fix, but whatever name with that idea in mind would do for me.

app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)
app.logger.info("Add ProxyFix to serve swagger.json over https.")