config.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. """The Pynecone config."""
  2. import os
  3. import sys
  4. from typing import List, Optional
  5. from pynecone import constants
  6. from pynecone.base import Base
  7. class Config(Base):
  8. """A Pynecone config."""
  9. # The name of the app.
  10. app_name: str
  11. # The username.
  12. username: Optional[str] = None
  13. # The frontend port.
  14. port: str = constants.FRONTEND_PORT
  15. # The frontend port.
  16. backend_port: str = constants.BACKEND_PORT
  17. # The backend API url.
  18. api_url: str = constants.API_URL
  19. # The deploy url.
  20. deploy_url: Optional[str] = None
  21. # The database url.
  22. db_url: Optional[str] = constants.DB_URL
  23. # The redis url.
  24. redis_url: Optional[str] = None
  25. # Telemetry opt-in.
  26. telemetry_enabled: bool = True
  27. # The pcdeploy url.
  28. pcdeploy_url: Optional[str] = None
  29. # The environment mode.
  30. env: constants.Env = constants.Env.DEV
  31. # The path to the bun executable.
  32. bun_path: str = constants.BUN_PATH
  33. # Disable bun.
  34. disable_bun: bool = False
  35. # Additional frontend packages to install.
  36. frontend_packages: List[str] = []
  37. # Backend transport methods.
  38. backend_transports: Optional[
  39. constants.Transports
  40. ] = constants.Transports.WEBSOCKET_POLLING
  41. # List of origins that are allowed to connect to the backend API.
  42. cors_allowed_origins: Optional[list] = [constants.CORS_ALLOWED_ORIGINS]
  43. # Whether credentials (cookies, authentication) are allowed in requests to the backend API.
  44. cors_credentials: Optional[bool] = True
  45. # The maximum size of a message when using the polling backend transport.
  46. polling_max_http_buffer_size: Optional[int] = constants.POLLING_MAX_HTTP_BUFFER_SIZE
  47. def get_config() -> Config:
  48. """Get the app config.
  49. Returns:
  50. The app config.
  51. """
  52. from pynecone.config import Config
  53. sys.path.append(os.getcwd())
  54. try:
  55. return __import__(constants.CONFIG_MODULE).config
  56. except ImportError:
  57. return Config(app_name="") # type: ignore