dify/api/config.py

43 lines
961 B
Python
Raw Normal View History

2023-05-15 08:51:32 +08:00
import os
import dotenv
DEFAULTS = {
}
def get_env(key):
return os.environ.get(key, DEFAULTS.get(key))
def get_bool_env(key):
value = get_env(key)
return value.lower() == 'true' if value is not None else False
2023-05-15 08:51:32 +08:00
def get_cors_allow_origins(env, default):
cors_allow_origins = []
if get_env(env):
for origin in get_env(env).split(','):
cors_allow_origins.append(origin)
else:
cors_allow_origins = [default]
return cors_allow_origins
class Config:
"""Application configuration class."""
def __init__(self):
dotenv.load_dotenv()
2023-05-15 08:51:32 +08:00
self.TESTING = False
self.APPLICATION_NAME = "langgenius/dify"
2024-04-18 17:33:32 +08:00
# cors settings
self.CONSOLE_CORS_ALLOW_ORIGINS = get_cors_allow_origins(
'CONSOLE_CORS_ALLOW_ORIGINS', get_env('CONSOLE_WEB_URL'))
self.WEB_API_CORS_ALLOW_ORIGINS = get_cors_allow_origins(
'WEB_API_CORS_ALLOW_ORIGINS', '*')