Skip to content

Commit 26af879

Browse files
committed
Add simple routes example app
1 parent 5b17da8 commit 26af879

File tree

8 files changed

+220
-0
lines changed

8 files changed

+220
-0
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ dependencies = [
88
"gunicorn>=23.0.0",
99
"shiny>=1.2.1",
1010
]
11+
12+
[tool.uv.workspace]
13+
members = ["routes_example_app"]

routes_example_app/.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.venv/
2+
Dockerfile
3+

routes_example_app/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM python:3.11
2+
3+
RUN pip install uv
4+
5+
COPY ./ opt/shiny
6+
7+
WORKDIR /opt/shiny
8+
9+
RUN uv sync
10+
11+
EXPOSE 3333
12+
13+
CMD [".venv/bin/gunicorn", "app:app", "-w 4", "-k uvicorn.workers.UvicornWorker", "-b 0.0.0.0:3333"]
14+

routes_example_app/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Routes Example App
2+
3+
```bash
4+
gunicorn app:app -w 4 -k uvicorn.workers.UvicornWorker
5+
```

routes_example_app/app.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from fastapi import FastAPI
2+
from shiny import App, ui
3+
from starlette.applications import Starlette
4+
from starlette.routing import Mount
5+
6+
# ---
7+
app_fastapi = FastAPI()
8+
9+
10+
@app_fastapi.get("/")
11+
def index():
12+
return dict(name="my-awesome-api", version="1.0.0")
13+
14+
15+
# ---
16+
app_shiny = App(ui.page_fluid("hello from shiny!"), None)
17+
18+
# ---
19+
routes = [Mount("/api", app=app_fastapi), Mount("/", app=app_shiny)]
20+
21+
app = Starlette(routes=routes)

routes_example_app/hello.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def main():
2+
print("Hello from routes-example-app!")
3+
4+
5+
if __name__ == "__main__":
6+
main()

routes_example_app/pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[project]
2+
name = "routes-example-app"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.9"
7+
dependencies = [
8+
"fastapi>=0.115.8",
9+
"gunicorn>=23.0.0",
10+
"shiny>=1.2.1",
11+
]

uv.lock

Lines changed: 157 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)