新建小程序后端,新建数据库
This commit is contained in:
35
mini-program/app/main.py
Normal file
35
mini-program/app/main.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import os
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
try:
|
||||
# For module mode: `uvicorn app.main:app`
|
||||
from app.routers.health import router as health_router
|
||||
from app.settings import settings
|
||||
except ModuleNotFoundError:
|
||||
# For script mode: `python app/main.py` or VS Code "Run Python File"
|
||||
from routers.health import router as health_router
|
||||
from settings import settings
|
||||
|
||||
|
||||
def create_app() -> FastAPI:
|
||||
app = FastAPI(
|
||||
title=settings.app_name,
|
||||
version=settings.app_version,
|
||||
description=settings.app_description,
|
||||
)
|
||||
app.include_router(health_router)
|
||||
return app
|
||||
|
||||
|
||||
app = create_app()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run(
|
||||
app,
|
||||
host=os.getenv("HOST", settings.host),
|
||||
port=int(os.getenv("PORT", str(settings.port))),
|
||||
)
|
||||
Reference in New Issue
Block a user