文档部分基本完成,还需要完善生成目录
This commit is contained in:
1 parent
578109c8de
commit
115fd47bae
108 files changed
+6202
-289
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import fastapi
|
||||
import uvicorn
|
||||
import toml
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
app = fastapi.FastAPI()
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins="*",
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
|
||||
class Config:
|
||||
_instance = None
|
||||
config = None
|
||||
|
||||
def __new__(cls):
|
||||
if not cls._instance:
|
||||
cls._instance = super().__new__(cls)
|
||||
cls.config = toml.load("config.toml")
|
||||
else:
|
||||
return cls._instance
|
||||
|
||||
def __init__():
|
||||
pass
|
||||
|
||||
|
||||
Config()
|
||||
|
||||
app.mount("/", StaticFiles(directory=Config.config["server"]["path"]), name="static")
|
||||
|
||||
|
||||
@app.get("/ping")
|
||||
def ping():
|
||||
return {"message": "pong!"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run(
|
||||
app, host=Config.config["server"]["host"], port=Config.config["server"]["port"]
|
||||
)
|
||||
Reference in new issue
Block a user