Add modular app structure for L1 server refactoring
Phase 2 of the full modernization: - App factory pattern with create_app() - Settings via dataclass with env vars - Dependency injection container - Router stubs for auth, storage, api, recipes, cache, runs - Service layer stubs for run, recipe, cache - Repository layer placeholder Routes are stubs that import from legacy server.py during migration. Next: Migrate each router fully with templates. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
49
app/routers/home.py
Normal file
49
app/routers/home.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""
|
||||
Home and root routes for L1 server.
|
||||
"""
|
||||
|
||||
from fastapi import APIRouter, Request, Depends
|
||||
from fastapi.responses import HTMLResponse, RedirectResponse
|
||||
|
||||
from artdag_common import render
|
||||
from artdag_common.middleware import wants_html
|
||||
|
||||
from ..dependencies import get_templates, get_current_user
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/")
|
||||
async def home(request: Request):
|
||||
"""
|
||||
Home page - redirect to runs if authenticated, show landing otherwise.
|
||||
"""
|
||||
user = await get_current_user(request)
|
||||
|
||||
if user:
|
||||
return RedirectResponse(url="/runs", status_code=302)
|
||||
|
||||
# For now, redirect to login at L2
|
||||
# TODO: Show a landing page with login link
|
||||
return RedirectResponse(url="/runs", status_code=302)
|
||||
|
||||
|
||||
@router.get("/login")
|
||||
async def login_redirect(request: Request):
|
||||
"""
|
||||
Redirect to L2 for login.
|
||||
"""
|
||||
from ..config import settings
|
||||
|
||||
if settings.l2_server:
|
||||
# Redirect to L2 login with return URL
|
||||
return_url = str(request.url_for("auth_callback"))
|
||||
login_url = f"{settings.l2_server}/login?return_to={return_url}"
|
||||
return RedirectResponse(url=login_url, status_code=302)
|
||||
|
||||
# No L2 configured - show error
|
||||
return HTMLResponse(
|
||||
"<html><body><h1>Login not configured</h1>"
|
||||
"<p>No L2 server configured for authentication.</p></body></html>",
|
||||
status_code=503
|
||||
)
|
||||
Reference in New Issue
Block a user