From 5390dae9370cbfc4a95ee2811b924e79e73411f0 Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Wed, 11 Oct 2023 02:06:38 +0200 Subject: [PATCH] Added cors --- requirements.txt | 3 ++- src/main.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 10678f7..c8cbd80 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ gpiozero luma.led_matrix fastapi -uvicorn \ No newline at end of file +uvicorn +fastapi-cors \ No newline at end of file diff --git a/src/main.py b/src/main.py index e43181b..4bcf876 100644 --- a/src/main.py +++ b/src/main.py @@ -2,10 +2,26 @@ from fastapi import FastAPI, HTTPException from datetime import datetime import requests from matrix import MatrixDisplay +from fastapi.middleware.cors import CORSMiddleware import asyncio app = FastAPI() +origins = [ + "http://localhost", + "http://localhost:8000", + "http://raspberrypi", + "http://192.168.178.54" +] + +app.add_middleware( + CORSMiddleware, + allow_origins=origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + matrix_display = MatrixDisplay() should_run_time_loop = True