Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,19 @@
|
|
| 1 |
-
from
|
| 2 |
|
| 3 |
-
app =
|
| 4 |
|
| 5 |
-
@app.
|
| 6 |
-
def
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
if __name__ == '__main__':
|
| 15 |
-
# Run the Flask server on port 5000 with debug mode enabled
|
| 16 |
-
app.run(debug=True, port=5000)
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request
|
| 2 |
|
| 3 |
+
app = FastAPI()
|
| 4 |
|
| 5 |
+
@app.post("/")
|
| 6 |
+
async def log_json(request: Request):
|
| 7 |
+
try:
|
| 8 |
+
# Parse the JSON body from the request
|
| 9 |
+
json_body = await request.json()
|
| 10 |
+
# Log the JSON payload to the console
|
| 11 |
+
print("Received JSON payload:", json_body)
|
| 12 |
+
# Respond with a success message
|
| 13 |
+
return {"status": "success", "message": "JSON payload logged successfully"}
|
| 14 |
+
except Exception as e:
|
| 15 |
+
# Handle cases where the request body is not valid JSON
|
| 16 |
+
print("Failed to parse JSON payload:", e)
|
| 17 |
+
return {"status": "error", "message": "Invalid JSON payload"}, 400
|
| 18 |
+
:contentReference[oaicite:2]{index=2}
|
| 19 |
|
|
|
|
|
|
|
|
|