Skip to content

Commit

Permalink
Add docs for mounting Mesop app (#892)
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwillchen authored Aug 29, 2024
1 parent 41c919c commit 183450d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
21 changes: 21 additions & 0 deletions docs/guides/server-integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Server integration

Mesop allows you to integrate Mesop with other Python web servers like FastAPI or Flask by mounting the Mesop app which is a [WSGI](https://wsgi.readthedocs.io/en/latest/what.html) app.

This enables you to do things like:

- Serve local files (e.g. images)
- Provide API endpoints (which can be called by the web component, etc.)

## API

The main API for doing this integration is the `create_wsgi_app` function.

::: mesop.server.wsgi_app.create_wsgi_app

## FastAPI example

For a working example of using Mesop with FastAPI, please take a look at this repo:
[https://github.com/wwwillchen/mesop-fastapi](https://github.com/wwwillchen/mesop-fastapi)

> Note: you can apply similar steps to use any other web framework that allows you to mount a WSGI app.
5 changes: 4 additions & 1 deletion mesop/server/wsgi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ def create_app(

def create_wsgi_app(*, debug_mode: bool = False):
"""
Creates a WSGI app that can be used to run Mesop in a WSGI server.
Creates a WSGI app that can be used to run Mesop in a WSGI server like gunicorn.
Args:
debug_mode: If True, enables debug mode for the Mesop app.
"""
_app = None

Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ nav:
- Multi-Pages: guides/multi-pages.md
- Auth: guides/auth.md
- Theming: guides/theming.md
- Server integration: guides/server-integration.md
- Development:
- Debugging: guides/debugging.md
- Testing: guides/testing.md
Expand Down

0 comments on commit 183450d

Please sign in to comment.