Skip to content

Expose dashboard as a mountable starlette app#76

Open
jklaise wants to merge 2 commits intoTkTech:26_uxfrom
jklaise:expose-dashboard-as-starlette-app
Open

Expose dashboard as a mountable starlette app#76
jklaise wants to merge 2 commits intoTkTech:26_uxfrom
jklaise:expose-dashboard-as-starlette-app

Conversation

@jklaise
Copy link
Contributor

@jklaise jklaise commented Jan 19, 2026

Adds support for #64.

Full disclosure - I'm not familiar with React development, so for the frontend wiring I have relied on ChatGPT. There are also a bunch of formatting changes made automatically by my IDE - I re-ran npm run lint -- --fix but this didn't change the formatting back.

Basic idea:

  • Ship chancy-config.js and expose it over the API so that the backend server can tell the (statically bundled) frontend under what prefix it is running
  • Provide utilities in config.ts that are used elsewhere to make all route references relative to the base path with the prefix

An example FastAPI app with the dashboard mounted as a subapp:

# app.py
from contextlib import asynccontextmanager

from fastapi import FastAPI

from chancy import Chancy, Worker
from chancy.plugins.api import Api, SimpleAuthBackend

# Configure your Chancy instance as you normally would.
CHANCY_DSN = "postgresql://localhost:5432/dev"

# Auth + path prefix for the mounted dashboard/API
api_plugin = Api(
    authentication_backend=SimpleAuthBackend({"admin": "password"}),
    path_prefix="/chancy",
    allow_origins=["*"],
)

chancy = Chancy(CHANCY_DSN)


@asynccontextmanager
async def lifespan(app: FastAPI):
    async with chancy:
        async with Worker(chancy) as worker:
            # Build the Starlette app once and mount it under the same prefix
            api_app = api_plugin.build_starlette_app(worker, chancy)
            app.mount(api_plugin.path_prefix or "/", api_app)

            yield


app = FastAPI(lifespan=lifespan)


@app.get("/ping")
async def ping():
    return {"pong": True}


if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host="127.0.0.1", port=8000)

@codecov
Copy link

codecov bot commented Jan 19, 2026

Codecov Report

❌ Patch coverage is 0% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.76%. Comparing base (31cc61d) to head (4d45dab).

Files with missing lines Patch % Lines
chancy/plugins/api/__init__.py 0.00% 25 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            26_ux      #76      +/-   ##
==========================================
+ Coverage   66.71%   66.76%   +0.05%     
==========================================
  Files          59       59              
  Lines        3506     3563      +57     
==========================================
+ Hits         2339     2379      +40     
- Misses       1167     1184      +17     
Flag Coverage Δ
unittests 66.76% <0.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@TkTech TkTech added this to the 0.26.0 milestone Jan 20, 2026
@TkTech TkTech added the enhancement New feature or request label Jan 20, 2026
name=route["name"],
)

async def prefix_config(request):
Copy link
Owner

Choose a reason for hiding this comment

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

This seems reasonable overall. We should probably pass the port through as well.

@TkTech
Copy link
Owner

TkTech commented Jan 28, 2026

Overall I don't see any glaring issues - we should probably pass through the port as well, and we'll need to add a short doc page on mounting under a sub-path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants