added frontend build initialization in backend startup logic, updated imports and threading setup
This commit is contained in:
@@ -15,6 +15,8 @@ import sqlite3
|
||||
import time
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Any, Dict, List, Union
|
||||
import subprocess
|
||||
import threading
|
||||
|
||||
# Third-party imports
|
||||
import httpx
|
||||
@@ -62,6 +64,19 @@ scheduler.add_job(
|
||||
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
|
||||
@app.get("/news", response_model=List[Dict[str, Any]])
|
||||
async def get_news(
|
||||
@@ -200,8 +215,6 @@ async def list_feeds(db: sqlite3.Cursor = Depends(get_db)):
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
@app.post("/feeds", response_model=SuccessResponse)
|
||||
async def add_feed(
|
||||
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)
|
||||
async def get_last_sync(db: sqlite3.Cursor = Depends(get_db)):
|
||||
"""
|
||||
@@ -406,5 +418,11 @@ async def update_cron_schedule(
|
||||
return {"hours": hours}
|
||||
|
||||
|
||||
# Mount static frontend
|
||||
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)
|
||||
|
||||
|
Reference in New Issue
Block a user