refactor: extract cors configs into dify config and cleanup the config class (#5507)

Co-authored-by: takatost <takatost@gmail.com>
This commit is contained in:
Bowen Liang
2024-06-25 15:48:02 +08:00
committed by GitHub
parent ec1d3ddee2
commit 2a0f03a511
8 changed files with 51 additions and 55 deletions

View File

@@ -15,6 +15,7 @@ def example_env_file(tmp_path, monkeypatch) -> str:
file_path.write_text(dedent(
"""
CONSOLE_API_URL=https://example.com
CONSOLE_WEB_URL=https://example.com
"""))
return str(file_path)
@@ -47,14 +48,13 @@ def test_flask_configs(example_env_file):
flask_app.config.from_mapping(DifyConfig(_env_file=example_env_file).model_dump())
config = flask_app.config
# configs read from dotenv directly
assert config['LOG_LEVEL'] == 'INFO'
# configs read from pydantic-settings
assert config['LOG_LEVEL'] == 'INFO'
assert config['COMMIT_SHA'] == ''
assert config['EDITION'] == 'SELF_HOSTED'
assert config['API_COMPRESSION_ENABLED'] is False
assert config['SENTRY_TRACES_SAMPLE_RATE'] == 1.0
assert config['TESTING'] == False
# value from env file
assert config['CONSOLE_API_URL'] == 'https://example.com'
@@ -71,3 +71,7 @@ def test_flask_configs(example_env_file):
'pool_recycle': 3600,
'pool_size': 30,
}
assert config['CONSOLE_WEB_URL']=='https://example.com'
assert config['CONSOLE_CORS_ALLOW_ORIGINS']==['https://example.com']
assert config['WEB_API_CORS_ALLOW_ORIGINS'] == ['*']