feat: basic web service by fastapi and uvicorn
This commit is contained in:
11
src/main.py
Normal file
11
src/main.py
Normal file
@@ -0,0 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# created by mmmy on 2025-09-27
|
||||
import uvicorn
|
||||
from web.api import api
|
||||
|
||||
# 主函数
|
||||
def main():
|
||||
uvicorn.run(api, host='0.0.0.0', port=8099)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
0
src/web/__init__.py
Normal file
0
src/web/__init__.py
Normal file
22
src/web/api.py
Normal file
22
src/web/api.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from typing import Any, Optional
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
api = FastAPI(title="Single People Management and Searching", version="0.1")
|
||||
api.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
class BaseResponse(BaseModel):
|
||||
error_code: int
|
||||
error_info: str
|
||||
data: Optional[Any] = None
|
||||
|
||||
@api.post("/ping")
|
||||
async def ping():
|
||||
return BaseResponse(error_code=0, error_info="success")
|
||||
Reference in New Issue
Block a user