Apollo commited on
Commit
c22a760
·
1 Parent(s): ae79671

Fix: Force root to serve index.html

Browse files
Files changed (1) hide show
  1. main.py +13 -33
main.py CHANGED
@@ -1,42 +1,22 @@
 
1
  from fastapi.responses import FileResponse
2
- from fastapi import FastAPI, HTTPException, Depends
3
- from pydantic import BaseModel
4
- from sqlalchemy import create_engine, Column, Integer, String
5
- from sqlalchemy.ext.declarative import declarative_base
6
- from sqlalchemy.orm import sessionmaker, Session
7
- from typing import List
8
  import os
9
 
10
- # Use an absolute path for the DB to ensure it persists in a Docker volume
11
- DATABASE_URL = "/data/crypto_whack.db"
12
- engine = create_engine(f"sqlite:///{DATABASE_URL}", connect_args={"check_same_thread": False})
13
- SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
14
- Base = declarative_base()
15
-
16
- class UserScore(Base):
17
- __tablename__ = "scores"
18
- user_id = Column(Integer, primary_key=True, index=True)
19
- username = Column(String)
20
- high_score = Column(Integer, default=0)
21
-
22
- # Ensure data directory exists
23
- os.makedirs("/data", exist_ok=True)
24
- Base.metadata.create_all(bind=engine)
25
-
26
  app = FastAPI()
27
 
28
- def get_db():
29
- db = SessionLocal()
30
- try:
31
- yield db
32
- finally:
33
- db.close()
34
-
35
- class ScoreUpdate(BaseModel):
36
- user_id: int
37
- username: str
38
- score: int
39
 
40
  @app.get("/")
41
  async def read_root():
42
  return FileResponse("index.html")
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
  from fastapi.responses import FileResponse
3
+ from fastapi.staticfiles import StaticFiles
4
+ import uvicorn
 
 
 
 
5
  import os
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  app = FastAPI()
8
 
9
+ # Mount the current directory to serve static files (logo.jpg, etc)
10
+ # we use check_file=False via a custom mount or just rely on the root get
11
+ app.mount("/static", StaticFiles(directory="."), name="static")
 
 
 
 
 
 
 
 
12
 
13
  @app.get("/")
14
  async def read_root():
15
  return FileResponse("index.html")
16
+
17
+ @app.get("/status")
18
+ async def status():
19
+ return {"status": "Crypto-Whack Backend Online (Hugging Face)"}
20
+
21
+ if __name__ == "__main__":
22
+ uvicorn.run(app, host="0.0.0.0", port=7860)