feat(api): project initialization

This commit is contained in:
bwstudio
2026-05-21 20:39:14 +08:00
commit 57245cc288
5 changed files with 72 additions and 0 deletions
View File
+13
View File
@@ -0,0 +1,13 @@
import os
# Database configuration
DATABASE_URL = "sqlite:///./joke.db"
# JWT configuration
JWT_SECRET_KEY = os.getenv("JWT_SECRET_KEY", "your-secret-key-change-in-production")
JWT_ALGORITHM = "HS256"
JWT_EXPIRATION_HOURS = 24
# API configuration
API_TITLE = "笑话大全 API"
API_VERSION = "1.0.0"
+26
View File
@@ -0,0 +1,26 @@
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from app.config import DATABASE_URL
# Create engine
engine = create_engine(
DATABASE_URL,
connect_args={"check_same_thread": False}
)
# Create SessionLocal class
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Create Base class
Base = declarative_base()
def get_db():
"""Dependency to get database session."""
db = SessionLocal()
try:
yield db
finally:
db.close()
+26
View File
@@ -0,0 +1,26 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.config import API_TITLE, API_VERSION
# Create FastAPI application
app = FastAPI(title=API_TITLE, version=API_VERSION)
# Configure CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
def root():
return {"message": "欢迎使用笑话大全 API"}
@app.get("/health")
def health_check():
return {"status": "healthy"}
+7
View File
@@ -0,0 +1,7 @@
fastapi==0.109.0
uvicorn[standard]==0.27.0
sqlalchemy==2.0.25
pydantic==2.5.3
python-jose[cryptography]==3.3.0
passlib[bcrypt]==1.7.4
python-multipart==0.0.6