From 35c8dfd21aabe3639e03587a01c2d38e831fc7e5 Mon Sep 17 00:00:00 2001 From: Elia el Lazkani Date: Tue, 24 Dec 2024 01:29:35 +0100 Subject: [PATCH] enh(): Adds configurable CORS * Adds CORS configuration in the config file * Enables CORS to be toggled through config --- config/config.yaml | 1 + shortenit/web.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/config/config.yaml b/config/config.yaml index aaddc77..93bfec7 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -1,6 +1,7 @@ Server: host: 127.0.0.1 port: 8000 + cors: False Web: host: 127.0.0.1 diff --git a/shortenit/web.py b/shortenit/web.py index 17b11d2..25a8030 100644 --- a/shortenit/web.py +++ b/shortenit/web.py @@ -23,7 +23,9 @@ class Web: def init(self): self.app = Flask(__name__) self.setup_routes() - CORS(self.app) + if server_config and server_config.get("cors", False): + self.logger.debug("Enabling CORS...") + CORS(self.app) def setup_routes(self): self.app.add_url_rule("/", "/", self.handler.index, methods=["GET"])