初始化fastapi项目

This commit is contained in:
xiaohei 2025-02-04 19:51:10 +08:00
parent 3ae49d336e
commit d1a2fea5db
4 changed files with 32 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
venv/
__pycache__/

13
Dockerfile Normal file
View File

@ -0,0 +1,13 @@
FROM python:3.11-alpine
WORKDIR /code
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade -r requirements.txt
COPY ./app /code
EXPOSE 8000
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

15
app/main.py Normal file
View File

@ -0,0 +1,15 @@
import fastapi
import uvicorn
app = fastapi.FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
fastapi~=0.115.8
uvicorn~=0.34.0