config.py 961 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import os
  2. import dotenv
  3. DEFAULTS = {
  4. }
  5. def get_env(key):
  6. return os.environ.get(key, DEFAULTS.get(key))
  7. def get_bool_env(key):
  8. value = get_env(key)
  9. return value.lower() == 'true' if value is not None else False
  10. def get_cors_allow_origins(env, default):
  11. cors_allow_origins = []
  12. if get_env(env):
  13. for origin in get_env(env).split(','):
  14. cors_allow_origins.append(origin)
  15. else:
  16. cors_allow_origins = [default]
  17. return cors_allow_origins
  18. class Config:
  19. """Application configuration class."""
  20. def __init__(self):
  21. dotenv.load_dotenv()
  22. self.TESTING = False
  23. self.APPLICATION_NAME = "langgenius/dify"
  24. # cors settings
  25. self.CONSOLE_CORS_ALLOW_ORIGINS = get_cors_allow_origins(
  26. 'CONSOLE_CORS_ALLOW_ORIGINS', get_env('CONSOLE_WEB_URL'))
  27. self.WEB_API_CORS_ALLOW_ORIGINS = get_cors_allow_origins(
  28. 'WEB_API_CORS_ALLOW_ORIGINS', '*')