File tree Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -31,4 +31,7 @@ flask_sqlalchemy==2.4.1
3131requests==2.23.0
3232
3333# The Debug Toolbar
34- Flask-DebugToolbar==0.11.0
34+ Flask-DebugToolbar==0.11.0
35+
36+ #CORS
37+ flask-cors==3.0.8
Original file line number Diff line number Diff line change 11from setuptools import setup , find_packages
22
33setup (
4- name = "time-tracker-api " ,
4+ name = "time-tracker-backend " ,
55 packages = find_packages (),
66 include_package_data = True ,
77)
Original file line number Diff line number Diff line change @@ -45,8 +45,12 @@ def init_app(app: Flask):
4545 app .logger .setLevel (logging .INFO )
4646 add_debug_toolbar (app )
4747
48+ cors_origins = app .config .get ('CORS_ORIGINS' )
49+ if cors_origins :
50+ enable_cors (app , cors_origins )
4851
49- def add_debug_toolbar (app ):
52+
53+ def add_debug_toolbar (app : Flask ):
5054 app .config ['DEBUG_TB_PANELS' ] = (
5155 'flask_debugtoolbar.panels.versions.VersionDebugPanel' ,
5256 'flask_debugtoolbar.panels.timer.TimerDebugPanel' ,
@@ -62,3 +66,10 @@ def add_debug_toolbar(app):
6266 from flask_debugtoolbar import DebugToolbarExtension
6367 toolbar = DebugToolbarExtension ()
6468 toolbar .init_app (app )
69+
70+
71+ def enable_cors (app : Flask , cors_origins : str ):
72+ from flask_cors import CORS
73+ cors_origins_list = cors_origins .split ("," )
74+ CORS (app , resources = {r"/*" : {"origins" : cors_origins_list }})
75+ app .logger .info ("Set CORS access to [%s]" % cors_origins )
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ class Config:
1111 PROPAGATE_EXCEPTIONS = True
1212 RESTPLUS_VALIDATE = True
1313 DEBUG = True
14+ CORS_ORIGINS = "*"
1415
1516
1617class DevelopmentConfig (Config ):
You can’t perform that action at this time.
0 commit comments