added frontend build initialization in backend startup logic, updated imports and threading setup

This commit is contained in:
2025-08-04 22:54:02 +02:00
parent 26c3cc79d7
commit 99ef24076e

View File

@@ -15,6 +15,8 @@ import sqlite3
import time import time
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from typing import Any, Dict, List, Union from typing import Any, Dict, List, Union
import subprocess
import threading
# Third-party imports # Third-party imports
import httpx import httpx
@@ -62,6 +64,19 @@ scheduler.add_job(
scheduler.start() scheduler.start()
def start_frontend_build():
try:
subprocess.Popen(
["yarn", "build"],
cwd="../frontend",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
print("Frontend build started successfully")
except Exception as e:
print(f"Failed to start frontend build: {e}")
# API endpoints # API endpoints
@app.get("/news", response_model=List[Dict[str, Any]]) @app.get("/news", response_model=List[Dict[str, Any]])
async def get_news( async def get_news(
@@ -200,8 +215,6 @@ async def list_feeds(db: sqlite3.Cursor = Depends(get_db)):
) )
@app.post("/feeds", response_model=SuccessResponse) @app.post("/feeds", response_model=SuccessResponse)
async def add_feed( async def add_feed(
feed: FeedData, feed: FeedData,
@@ -332,7 +345,6 @@ async def manual_sync(db: sqlite3.Cursor = Depends(get_db_write)): # Note: chan
) )
@app.get("/meta/last-sync", response_model=TimestampResponse) @app.get("/meta/last-sync", response_model=TimestampResponse)
async def get_last_sync(db: sqlite3.Cursor = Depends(get_db)): async def get_last_sync(db: sqlite3.Cursor = Depends(get_db)):
""" """
@@ -406,5 +418,11 @@ async def update_cron_schedule(
return {"hours": hours} return {"hours": hours}
# Mount static frontend
app.mount("/", StaticFiles(directory=frontend_path, html=True), name="static") app.mount("/", StaticFiles(directory=frontend_path, html=True), name="static")
if __name__ == "__main__":
threading.Thread(target=start_frontend_build, daemon=True).start()
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)