From e73cab566ca6f40c213c9a42d34d8f6af8515589 Mon Sep 17 00:00:00 2001
From: stuppie
Date: Thu, 17 Sep 2026 10:05:48 -0600
Subject: render_base_html to server base html with js file templated
---
jb/main.py | 27 ++-------------------------
jb/settings.py | 12 +++++++++---
jb/views/auth.py | 6 +++---
jb/views/common.py | 6 +++---
templates/base.html | 6 +++---
5 files changed, 20 insertions(+), 37 deletions(-)
diff --git a/jb/main.py b/jb/main.py
index 325bf53..945b22c 100644
--- a/jb/main.py
+++ b/jb/main.py
@@ -7,7 +7,7 @@ from starlette.middleware.cors import CORSMiddleware
from starlette.middleware.trustedhost import TrustedHostMiddleware
from jb.config import settings
-from jb.settings import BASE_HTML, load_manifest
+from jb.settings import render_base_html
from jb.views.auth import auth_router
from jb.views.common import common_router
@@ -45,33 +45,10 @@ def return_nothing() -> dict[str, Any]:
@app.get("/{full_path:path}")
def serve_react_app(full_path: str):
-
- manifest = load_manifest()
- entry = manifest["src/main.tsx"]
- js_file = entry["file"]
- css_file = manifest["style.css"]["file"]
-
- html = f"""
-
-
-
-
- James Billings loves you.
-
-
-
-
-
-
- """
-
# This serves index.html for any unmatched route
# React Router will then handle the client-side routing
return HTMLResponse(
- html,
+ render_base_html(),
headers={
"Cache-Control": "no-cache, no-store, must-revalidate",
"Pragma": "no-cache",
diff --git a/jb/settings.py b/jb/settings.py
index 1bf65bc..779bd85 100644
--- a/jb/settings.py
+++ b/jb/settings.py
@@ -2,7 +2,6 @@ import json
from functools import lru_cache
from os.path import abspath
from os.path import dirname as pdirname
-from os.path import join as pjoin
from pathlib import Path
from generalresearch.config import GRLBaseSettings, is_debug
@@ -16,7 +15,6 @@ from pydantic_settings import SettingsConfigDict
BASE_DIR = pdirname(pdirname(abspath(__file__)))
BASE_HTML_PATH = Path(BASE_DIR) / "templates" / "base.html"
-BASE_HTML = BASE_HTML_PATH.read_text()
MANIFEST_PATH = Path(BASE_DIR) / "jb-ui" / "dist/.vite/manifest.json"
@@ -25,8 +23,16 @@ def load_manifest():
return json.load(f)
-class Settings(GRLBaseSettings):
+def render_base_html() -> str:
+ manifest = load_manifest()
+ return (
+ BASE_HTML_PATH.read_text()
+ .replace("{{ css_file }}", manifest["style.css"]["file"])
+ .replace("{{ js_file }}", manifest["src/main.tsx"]["file"])
+ )
+
+class Settings(GRLBaseSettings):
model_config = SettingsConfigDict(
env_file=(".env.test", ".env.testing", ".env.staging", ".env.prod"),
env_file_encoding="utf-8",
diff --git a/jb/views/auth.py b/jb/views/auth.py
index 1b4c364..cc1224f 100644
--- a/jb/views/auth.py
+++ b/jb/views/auth.py
@@ -32,7 +32,7 @@ from jb.models.auth import (
MagicLinkExchangeRequest,
User,
)
-from jb.settings import BASE_HTML
+from jb.settings import render_base_html
auth_router = APIRouter(prefix="/auth", tags=["Auth"])
@@ -90,7 +90,7 @@ def magic_link_landing_page(
_exchange_magic_link(token, response, gr_api)
return response
return HTMLResponse(
- BASE_HTML,
+ render_base_html(),
headers={
"Cache-Control": "no-store",
"Referrer-Policy": "no-referrer",
@@ -180,7 +180,7 @@ def link_amt_account_landing_page(
_exchange_amt_account_link(token=token, response=_response, gr_api=gr_api)
return HTMLResponse(
- BASE_HTML,
+ render_base_html(),
headers={
"Cache-Control": "no-store",
"Referrer-Policy": "no-referrer",
diff --git a/jb/views/common.py b/jb/views/common.py
index 9eee453..f58acda 100644
--- a/jb/views/common.py
+++ b/jb/views/common.py
@@ -13,7 +13,7 @@ from jb.decorators import get_redis_config
from jb.flow.monitoring import emit_mturk_notification_event
from jb.models.auth import User
from jb.models.event import MTurkEvent
-from jb.settings import BASE_HTML
+from jb.settings import render_base_html
common_router = APIRouter(prefix="", tags=["API"], include_in_schema=True)
@@ -39,7 +39,7 @@ async def work(request: Request):
status_code=302,
)
- return HTMLResponse(BASE_HTML)
+ return HTMLResponse(render_base_html())
RedisConfigDep = Annotated[RedisConfig, Depends(get_redis_config)]
@@ -95,4 +95,4 @@ async def work_direct(
Makes sure user is authenticated.
"""
# todo: emit event
- return HTMLResponse(BASE_HTML)
+ return HTMLResponse(render_base_html())
diff --git a/templates/base.html b/templates/base.html
index c17972e..18bc851 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -6,11 +6,11 @@
content="width=device-width, initial-scale=1.0, height=device-height, minimum-scale=1.0, user-scalable=1">
James Billings loves you.
-
+
-