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

Custom API endpoints not working anymore #1099

Open
Jimmy-Newtron opened this issue Jun 24, 2024 · 2 comments
Open

Custom API endpoints not working anymore #1099

Jimmy-Newtron opened this issue Jun 24, 2024 · 2 comments

Comments

@Jimmy-Newtron
Copy link

          > This new way to handle resources access is breaking the custom endpoints that I add to the server

This is my solution to patch and temporarily fix the issue caused by the serve route

from chainlit.server import app
from starlette.routing import BaseRoute, Route

from src.core.routers import admin

routes: list[BaseRoute] = [
    r for r in app.router.routes if isinstance(r, Route) and r.name != "serve"
]

serve_route = [
    r for r in app.router.routes if isinstance(r, Route) and r.name == "serve"
]

app.router.routes = routes

app.include_router(admin.router)

app.router.routes.extend(serve_route)

Originally posted by @Jimmy-Newtron in #1064 (comment)

@haidersultancrewlogix
Copy link

I am also facing issues with Custom Endpoints with the new release. I can't use GET endpoints.
They route the base URL https:{HOST_NAME}:8000/ which is Chainlit Frontend.

@Jimmy-Newtron
Copy link
Author

Jimmy-Newtron commented Jun 26, 2024

The first code works partially, but the following forks better:

from chainlit.server import app
from prometheus_fastapi_instrumentator import Instrumentator
from starlette.routing import BaseRoute, Route

from src.core.routers import your_routers

serve_route: list[BaseRoute] = [
    r for r in app.router.routes if isinstance(r, Route) and r.name == "serve"
]

for route in serve_route:
    app.router.routes.remove(route)

app.include_router(your_routers)

Instrumentator().instrument(app).expose(app, tags=["monitoring"])

app.router.routes.extend(serve_route)

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

No branches or pull requests

2 participants