|
| 1 | +import secrets |
1 | 2 | import typing as t |
2 | 3 |
|
3 | 4 | from ellar.common import EllarInterceptor, GuardCanActivate |
@@ -253,3 +254,60 @@ def pre_cache_validate(cls, value: t.Dict) -> t.Any: |
253 | 254 |
|
254 | 255 |
|
255 | 256 | ConfigSchema.model_rebuild() |
| 257 | + |
| 258 | + |
| 259 | +def default_config_settings(): |
| 260 | + from ellar.common import JSONResponse |
| 261 | + from ellar.core.versioning import DefaultAPIVersioning |
| 262 | + from ellar.pydantic import ENCODERS_BY_TYPE as encoders_by_type |
| 263 | + |
| 264 | + return { |
| 265 | + "DEBUG": False, |
| 266 | + "DEFAULT_JSON_CLASS": JSONResponse, |
| 267 | + "SECRET_KEY": secrets.token_hex(16), |
| 268 | + # injector auto_bind = True allows you to resolve types that are not registered on the container |
| 269 | + # For more info, read: https://injector.readthedocs.io/en/latest/index.html |
| 270 | + "INJECTOR_AUTO_BIND": False, |
| 271 | + # jinja Environment options |
| 272 | + # https://jinja.palletsprojects.com/en/3.0.x/api/#high-level-api |
| 273 | + "JINJA_TEMPLATES_OPTIONS": {}, |
| 274 | + # Injects context to jinja templating context values |
| 275 | + "TEMPLATES_CONTEXT_PROCESSORS": [ |
| 276 | + "ellar.core.templating.context_processors:request_context", |
| 277 | + "ellar.core.templating.context_processors:user", |
| 278 | + "ellar.core.templating.context_processors:request_state", |
| 279 | + ], |
| 280 | + # Application route versioning scheme |
| 281 | + "VERSIONING_SCHEME": DefaultAPIVersioning(), |
| 282 | + # Enable or Disable Application Router route searching by appending backslash |
| 283 | + "REDIRECT_SLASHES": False, |
| 284 | + # Define references to static folders in python packages. |
| 285 | + # eg STATIC_FOLDER_PACKAGES = [('boostrap4', 'statics')] |
| 286 | + "STATIC_FOLDER_PACKAGES": [], |
| 287 | + # Define references to static folders defined within the project |
| 288 | + "STATIC_DIRECTORIES": [], |
| 289 | + # static route path |
| 290 | + "STATIC_MOUNT_PATH": "/static", |
| 291 | + "CORS_ALLOW_ORIGINS": ["*"], |
| 292 | + "CORS_ALLOW_METHODS": ["*"], |
| 293 | + "CORS_ALLOW_HEADERS": ["*"], |
| 294 | + "ALLOWED_HOSTS": ["*"], |
| 295 | + # Application middlewares |
| 296 | + "MIDDLEWARE": [ |
| 297 | + "ellar.core.middleware.trusted_host:trusted_host_middleware", |
| 298 | + "ellar.core.middleware.cors:cors_middleware", |
| 299 | + "ellar.core.middleware.errors:server_error_middleware", |
| 300 | + "ellar.core.middleware.versioning:versioning_middleware", |
| 301 | + "ellar.auth.middleware.session:session_middleware", |
| 302 | + "ellar.auth.middleware.auth:identity_middleware", |
| 303 | + "ellar.core.middleware.exceptions:exception_middleware", |
| 304 | + ], |
| 305 | + # A dictionary mapping either integer status codes, |
| 306 | + # or exception class types onto callables which handle the exceptions. |
| 307 | + # Exception handler callables should be of the form |
| 308 | + # `handler(context:IExecutionContext, exc: Exception) -> response` |
| 309 | + # and may be either standard functions, or async functions. |
| 310 | + "EXCEPTION_HANDLERS": ["ellar.core.exceptions:error_404_handler"], |
| 311 | + # Object Serializer custom encoders |
| 312 | + "SERIALIZER_CUSTOM_ENCODER": encoders_by_type, |
| 313 | + } |
0 commit comments