trading_agent.gateway.routes.frontend_routes
¶
Serves the built web page, falling back to index.html for the page's own addresses.
The web page is a single-page React application: addresses such as /chat/main are handled in the browser, so the server answers each of them with index.html. Files the build produced, such as scripts and styles, are served as they are. Addresses under /api, /ws and /hooks are never answered with the page, so a mistyped API address gets a clear 404.
This route needs no access token: the page itself holds no data, and every request it makes for data carries the token.
Typical usage example:
application.include_router(FrontendRoutes(Path('frontend/dist')).router())
FrontendRoutes
¶
The catch-all route for the web page; it must be the last router added.
Creates the route.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frontend_directory
|
Path
|
The Vite build output folder. |
required |
Source code in src/trading_agent/gateway/routes/frontend_routes.py
router
¶
Builds the router holding the catch-all route.
Returns:
| Type | Description |
|---|---|
APIRouter
|
The router. |
Source code in src/trading_agent/gateway/routes/frontend_routes.py
serve
¶
Serves a built file, or index.html for any other page address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The requested path without the leading slash. |
required |
Returns:
| Type | Description |
|---|---|
Response
|
The file, index.html, or a page explaining that the web page is not built. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
The address is under /api, /ws or /hooks (status 404). |