From 9a6df51d763a5610607f6510e867393c1f467be3 Mon Sep 17 00:00:00 2001 From: Dita Aji Pratama Date: Sun, 29 Dec 2024 14:16:19 +0700 Subject: [PATCH] Add CORS configuration --- config/server.py | 5 ++++- costa.py | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config/server.py b/config/server.py index 3869aa3..cf89594 100644 --- a/config/server.py +++ b/config/server.py @@ -11,7 +11,10 @@ session_opts = { 'session.auto': True } -# cors +def enable_cors(): + response.headers['Access-Control-Allow-Origin' ] = '*' + response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS' + response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token, Authorization' # error page 403 # error page 404 diff --git a/costa.py b/costa.py index 8bc8677..48ebbf7 100644 --- a/costa.py +++ b/costa.py @@ -16,6 +16,10 @@ from config import server app = Bottle() +@app.hook('after_request') +def after_request(): + server.enable_cors() + app.merge(handler.app) app.merge(staticdir.app)