1
1
import os
2
- import importlib .util
3
- import sys
4
2
5
- def load_config ():
6
- config = {'ENV' : os .environ .get ('ENV' , 'DEVELOPMENT' )}
7
- config_base_path = './App'
8
-
9
- # Check for custom_config.py file; adjust path as needed
10
- custom_config_path = os .path .join (config_base_path , 'custom_config.py' )
11
- default_config_path = os .path .join (config_base_path , 'default_config.py' )
12
-
13
- if os .path .exists (custom_config_path ):
14
- spec = importlib .util .spec_from_file_location ("custom_config" , custom_config_path )
15
- else :
16
- spec = importlib .util .spec_from_file_location ("default_config" , default_config_path )
17
-
18
- config_module = importlib .util .module_from_spec (spec )
19
- sys .modules [spec .name ] = config_module
20
- spec .loader .exec_module (config_module )
21
-
22
- if config ['ENV' ] == "DEVELOPMENT" :
23
- config ['SQLALCHEMY_DATABASE_URI' ] = config_module .SQLALCHEMY_DATABASE_URI
24
- config ['SECRET_KEY' ] = config_module .SECRET_KEY
25
- config ['JWT_SECRET_KEY' ] = config_module .SECRET_KEY
3
+ def load_config (app , overrides ):
4
+ if os .path .exists (os .path .join ('./App' , 'custom_config.py' )):
5
+ app .config .from_object ('App.custom_config' )
26
6
else :
27
- config ['SQLALCHEMY_DATABASE_URI' ] = os .environ .get ('SQLALCHEMY_DATABASE_URI' , config_module .SQLALCHEMY_DATABASE_URI )
28
- config ['SECRET_KEY' ] = os .environ .get ('SECRET_KEY' , config_module .SECRET_KEY )
29
- config ['JWT_SECRET_KEY' ] = os .environ .get ('JWT_SECRET_KEY' , config_module .SECRET_KEY )
30
- config ['DEBUG' ] = config ['ENV' ].upper () != 'PRODUCTION'
31
-
32
- # Default configurations that don't depend on the environment
33
- config ['SQLALCHEMY_TRACK_MODIFICATIONS' ] = False
34
- config ['TEMPLATES_AUTO_RELOAD' ] = True
35
- config ['PREFERRED_URL_SCHEME' ] = 'https'
36
- config ['UPLOADED_PHOTOS_DEST' ] = "App/uploads"
37
-
38
- return config
39
-
40
- config = load_config ()
7
+ app .config .from_object ('App.default_config' )
8
+ app .config .from_prefixed_env ()
9
+ app .config ['SQLALCHEMY_TRACK_MODIFICATIONS' ] = False
10
+ app .config ['TEMPLATES_AUTO_RELOAD' ] = True
11
+ app .config ['PREFERRED_URL_SCHEME' ] = 'https'
12
+ app .config ['UPLOADED_PHOTOS_DEST' ] = "App/uploads"
13
+ app .config ['JWT_ACCESS_COOKIE_NAME' ] = 'access_token'
14
+ app .config ["JWT_TOKEN_LOCATION" ] = ["cookies" , "headers" ]
15
+ app .config ["JWT_COOKIE_SECURE" ] = True
16
+ app .config ["JWT_COOKIE_CSRF_PROTECT" ] = False
17
+ for key in overrides :
18
+ app .config [key ] = overrides [key ]
0 commit comments