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

build_starlette_app #75

Merged
merged 5 commits into from
Apr 21, 2021
Merged

build_starlette_app #75

merged 5 commits into from
Apr 21, 2021

Conversation

brumar
Copy link
Contributor

@brumar brumar commented Apr 20, 2021

Hello,

build_starlette_app is extracted from fastapi.start_server in order to be used by FastAPI users who want to include a plug-and-play experience of pywebio into their existing FastAPI application.

It provides an intermediary level between webio_routes (that does not handle static files) and start_server (that launches a uvicorn server).

Indeed start_server is not usable for some users running FastAPI in production using both gunicorn and uvicorn (such as in https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker)

Copy link
Member

@wang0618 wang0618 left a comment

Choose a reason for hiding this comment

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

Thanks for this! It's necessary to provide a function to just get backend app instance and not start server.

Here are some preliminary comments:

@@ -151,8 +151,41 @@ def start_server(applications, port=0, host='',

.. versionadded:: 1.3
"""
kwargs = locals()
app = build_starlette_app(allowed_origins, applications, cdn, check_origin, debug, static_dir)
Copy link
Member

Choose a reason for hiding this comment

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

It's better to use keyword arguments:

Suggested change
app = build_starlette_app(allowed_origins, applications, cdn, check_origin, debug, static_dir)
app = build_starlette_app(applications, cdn=cdn, static_dir=static_dir, debug=debug, allowed_origins=allowed_origins, check_origin=check_origin)

uvicorn.run(app, host=host, port=port)


def build_starlette_app(applications, cdn=True, static_dir=None, debug=False, allowed_origins=None, check_origin=None):
Copy link
Member

Choose a reason for hiding this comment

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

I think it's better to use asig_app as the function name:

Suggested change
def build_starlette_app(applications, cdn=True, static_dir=None, debug=False, allowed_origins=None, check_origin=None):
def asig_app(applications, cdn=True, static_dir=None, debug=False, allowed_origins=None, check_origin=None):

References to build_starlette_app() elsewhere also need to be modified accordingly

Because I plan to add wsgi_app() or asgi_app() to the other backend modules as well, , so it can keep the naming uniformity

Copy link
Member

@wang0618 wang0618 left a comment

Choose a reason for hiding this comment

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

A references to build_starlette_app() in doc was forgot to modify. Let me do it

pywebio/platform/__init__.py Outdated Show resolved Hide resolved
@brumar
Copy link
Contributor Author

brumar commented Apr 21, 2021

Hello @wang0618

Oh sorry, I forgot this one indeed.
I fully agree with the changes you requested.
In case you have not noticed I also passed the unused argument **uvicorn_settings to uvicorn.run

@codecov
Copy link

codecov bot commented Apr 21, 2021

Codecov Report

Merging #75 (ccbbc07) into dev (022a9cf) will increase coverage by 0.00%.
The diff coverage is 80.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##              dev      #75   +/-   ##
=======================================
  Coverage   87.96%   87.96%           
=======================================
  Files          22       22           
  Lines        2716     2717    +1     
=======================================
+ Hits         2389     2390    +1     
  Misses        327      327           
Impacted Files Coverage Δ
pywebio/platform/__init__.py 100.00% <ø> (ø)
pywebio/platform/fastapi.py 89.21% <80.00%> (+0.10%) ⬆️

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 022a9cf...ccbbc07. Read the comment docs.

@wang0618
Copy link
Member

In case you have not noticed I also passed the unused argument **uvicorn_settings to uvicorn.run

Thanks a lot. Didn't notice the bug before.

@wang0618 wang0618 merged commit 3e07ba6 into pywebio:dev Apr 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants