commit 97568607ca23a63eee1f8e7f26086ed5e809471c Author: moanos Date: Thu Apr 17 07:04:59 2025 +0200 first commit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3478264 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +# Dockerfile +FROM python:3.11-slim + +# Set working directory +WORKDIR /app + +# Install dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the entire project (app folder inside container too) +COPY . . + +# Expose port +EXPOSE 8000 + +# Run the server from within the "app" package +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000..3314f59 --- /dev/null +++ b/app/main.py @@ -0,0 +1,29 @@ +# app/main.py +from fastapi import FastAPI, Request +from datetime import datetime +from pathlib import Path +import json + +app = FastAPI() +DATA_FILE = Path("data.json") + + +@app.post("/submit") +async def submit_data(request: Request): + payload = await request.json() + + # Create the file if it doesn't exist + if not DATA_FILE.exists(): + with open(DATA_FILE, "w") as f: + json.dump([], f) + + with open(DATA_FILE, "r+", encoding="utf-8") as f: + existing_data = json.load(f) + existing_data.append({ + "timestamp": datetime.now().isoformat(), + "data": payload + }) + f.seek(0) + json.dump(existing_data, f, indent=4) + + return {"message": "Data saved successfully"} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..97dc7cd --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +fastapi +uvicorn diff --git a/test_main.http b/test_main.http new file mode 100644 index 0000000..a2d81a9 --- /dev/null +++ b/test_main.http @@ -0,0 +1,11 @@ +# Test your FastAPI endpoints + +GET http://127.0.0.1:8000/ +Accept: application/json + +### + +GET http://127.0.0.1:8000/hello/User +Accept: application/json + +###