|
1 | | -from ellar.core.conf import ConfigDefaultTypesMixin |
| 1 | +import typing as t |
2 | 2 |
|
| 3 | +from ellar.common import IExceptionHandler, JSONResponse |
| 4 | +from ellar.core import ConfigDefaultTypesMixin |
| 5 | +from ellar.core.versioning import BaseAPIVersioning, DefaultAPIVersioning |
| 6 | +from ellar.pydantic import ENCODERS_BY_TYPE as encoders_by_type |
| 7 | +from starlette.middleware import Middleware |
| 8 | +from starlette.requests import Request |
3 | 9 |
|
4 | | -class DevelopmentConfig(ConfigDefaultTypesMixin): |
5 | | - DEBUG = True |
6 | 10 |
|
| 11 | +class BaseConfig(ConfigDefaultTypesMixin): |
| 12 | + DEBUG: bool = False |
7 | 13 |
|
8 | | -class TestingConfig(ConfigDefaultTypesMixin): |
| 14 | + DEFAULT_JSON_CLASS: t.Type[JSONResponse] = JSONResponse |
| 15 | + SECRET_KEY: str = "ellar_QdZwHTfLkZQWQtAot-V6gbTHONMn3ekrl5jdcb5AOC8" |
| 16 | + |
| 17 | + # injector auto_bind = True allows you to resolve types that are not registered on the container |
| 18 | + # For more info, read: https://injector.readthedocs.io/en/latest/index.html |
| 19 | + INJECTOR_AUTO_BIND = False |
| 20 | + |
| 21 | + # jinja Environment options |
| 22 | + # https://jinja.palletsprojects.com/en/3.0.x/api/#high-level-api |
| 23 | + JINJA_TEMPLATES_OPTIONS: t.Dict[str, t.Any] = {} |
| 24 | + |
| 25 | + # Injects context to jinja templating context values |
| 26 | + TEMPLATES_CONTEXT_PROCESSORS: t.List[ |
| 27 | + t.Union[str, t.Callable[[t.Union[Request]], t.Dict[str, t.Any]]] |
| 28 | + ] = [ |
| 29 | + "ellar.core.templating.context_processors:request_context", |
| 30 | + "ellar.core.templating.context_processors:user", |
| 31 | + "ellar.core.templating.context_processors:request_state", |
| 32 | + ] |
| 33 | + |
| 34 | + # Application route versioning scheme |
| 35 | + VERSIONING_SCHEME: BaseAPIVersioning = DefaultAPIVersioning() |
| 36 | + |
| 37 | + # Enable or Disable Application Router route searching by appending backslash |
| 38 | + REDIRECT_SLASHES: bool = False |
| 39 | + |
| 40 | + # Define references to static folders in python packages. |
| 41 | + # eg STATIC_FOLDER_PACKAGES = [('boostrap4', 'statics')] |
| 42 | + STATIC_FOLDER_PACKAGES: t.Optional[t.List[t.Union[str, t.Tuple[str, str]]]] = [] |
| 43 | + |
| 44 | + # Define references to static folders defined within the project |
| 45 | + STATIC_DIRECTORIES: t.Optional[t.List[t.Union[str, t.Any]]] = [] |
| 46 | + |
| 47 | + # static route path |
| 48 | + STATIC_MOUNT_PATH: str = "/static" |
| 49 | + |
| 50 | + CORS_ALLOW_ORIGINS: t.List[str] = ["*"] |
| 51 | + CORS_ALLOW_METHODS: t.List[str] = ["*"] |
| 52 | + CORS_ALLOW_HEADERS: t.List[str] = ["*"] |
| 53 | + ALLOWED_HOSTS: t.List[str] = ["*"] |
| 54 | + |
| 55 | + # Application middlewares |
| 56 | + MIDDLEWARE: t.Union[str, Middleware] = [ |
| 57 | + "ellar.core.middleware.trusted_host:trusted_host_middleware", |
| 58 | + "ellar.core.middleware.cors:cors_middleware", |
| 59 | + "ellar.core.middleware.errors:server_error_middleware", |
| 60 | + "ellar.core.middleware.versioning:versioning_middleware", |
| 61 | + "ellar.auth.middleware.session:session_middleware", |
| 62 | + "ellar.auth.middleware.auth:identity_middleware", |
| 63 | + "ellar.core.middleware.exceptions:exception_middleware", |
| 64 | + ] |
| 65 | + |
| 66 | + # A dictionary mapping either integer status codes, |
| 67 | + # or exception class types onto callables which handle the exceptions. |
| 68 | + # Exception handler callables should be of the form |
| 69 | + # `handler(context:IExecutionContext, exc: Exception) -> response` |
| 70 | + # and may be either standard functions, or async functions. |
| 71 | + EXCEPTION_HANDLERS: t.Union[str, IExceptionHandler] = [ |
| 72 | + "ellar.core.exceptions:error_404_handler" |
| 73 | + ] |
| 74 | + |
| 75 | + # Object Serializer custom encoders |
| 76 | + SERIALIZER_CUSTOM_ENCODER: t.Dict[t.Any, t.Callable[[t.Any], t.Any]] = ( |
| 77 | + encoders_by_type |
| 78 | + ) |
| 79 | + |
| 80 | + |
| 81 | +class DevelopmentConfig(BaseConfig): |
| 82 | + DEBUG: bool = True |
| 83 | + |
| 84 | + |
| 85 | +class TestingConfig(BaseConfig): |
9 | 86 | DEBUG = False |
0 commit comments