Skip to content

Commit 98aeb1f

Browse files
committed
Added docs for default config
1 parent 8f5a1dd commit 98aeb1f

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

docs/techniques/configurations.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,91 @@ application = AppFactory.create_from_app_module(
304304
)
305305
)
306306
```
307+
308+
## **Complete Configuration Example**
309+
310+
Below is a complete configuration example showing all available configuration options with their default values:
311+
312+
```python
313+
import typing as t
314+
315+
from ellar.common import IExceptionHandler, JSONResponse
316+
from ellar.core import ConfigDefaultTypesMixin
317+
from ellar.core.versioning import BaseAPIVersioning, DefaultAPIVersioning
318+
from ellar.pydantic import ENCODERS_BY_TYPE as encoders_by_type
319+
from starlette.middleware import Middleware
320+
from starlette.requests import Request
321+
322+
323+
class BaseConfig(ConfigDefaultTypesMixin):
324+
DEBUG: bool = False
325+
326+
DEFAULT_JSON_CLASS: t.Type[JSONResponse] = JSONResponse
327+
SECRET_KEY: str = "your-secret-key-here"
328+
329+
# injector auto_bind = True allows you to resolve types that are not registered on the container
330+
# For more info, read: https://injector.readthedocs.io/en/latest/index.html
331+
INJECTOR_AUTO_BIND = False
332+
333+
# jinja Environment options
334+
# https://jinja.palletsprojects.com/en/3.0.x/api/#high-level-api
335+
JINJA_TEMPLATES_OPTIONS: t.Dict[str, t.Any] = {}
336+
337+
# Injects context to jinja templating context values
338+
TEMPLATES_CONTEXT_PROCESSORS: t.List[
339+
t.Union[str, t.Callable[[t.Union[Request]], t.Dict[str, t.Any]]]
340+
] = [
341+
"ellar.core.templating.context_processors:request_context",
342+
"ellar.core.templating.context_processors:user",
343+
"ellar.core.templating.context_processors:request_state",
344+
]
345+
346+
# Application route versioning scheme
347+
VERSIONING_SCHEME: BaseAPIVersioning = DefaultAPIVersioning()
348+
349+
# Enable or Disable Application Router route searching by appending backslash
350+
REDIRECT_SLASHES: bool = False
351+
352+
# Define references to static folders in python packages.
353+
# eg STATIC_FOLDER_PACKAGES = [('boostrap4', 'statics')]
354+
STATIC_FOLDER_PACKAGES: t.Optional[t.List[t.Union[str, t.Tuple[str, str]]]] = []
355+
356+
# Define references to static folders defined within the project
357+
STATIC_DIRECTORIES: t.Optional[t.List[t.Union[str, t.Any]]] = []
358+
359+
# static route path
360+
STATIC_MOUNT_PATH: str = "/static"
361+
362+
CORS_ALLOW_ORIGINS: t.List[str] = ["*"]
363+
CORS_ALLOW_METHODS: t.List[str] = ["*"]
364+
CORS_ALLOW_HEADERS: t.List[str] = ["*"]
365+
ALLOWED_HOSTS: t.List[str] = ["*"]
366+
367+
# Application middlewares
368+
MIDDLEWARE: t.List[t.Union[str, Middleware]] = [
369+
"ellar.core.middleware.trusted_host:trusted_host_middleware",
370+
"ellar.core.middleware.cors:cors_middleware",
371+
"ellar.core.middleware.errors:server_error_middleware",
372+
"ellar.core.middleware.versioning:versioning_middleware",
373+
"ellar.auth.middleware.session:session_middleware",
374+
"ellar.auth.middleware.auth:identity_middleware",
375+
"ellar.core.middleware.exceptions:exception_middleware",
376+
]
377+
378+
# A dictionary mapping either integer status codes,
379+
# or exception class types onto callables which handle the exceptions.
380+
# Exception handler callables should be of the form
381+
# `handler(context:IExecutionContext, exc: Exception) -> response`
382+
# and may be either standard functions, or async functions.
383+
EXCEPTION_HANDLERS: t.List[t.Union[str, IExceptionHandler]] = [
384+
"ellar.core.exceptions:error_404_handler"
385+
]
386+
387+
# Object Serializer custom encoders
388+
SERIALIZER_CUSTOM_ENCODER: t.Dict[t.Any, t.Callable[[t.Any], t.Any]] = (
389+
encoders_by_type
390+
)
391+
```
392+
393+
!!! tip
394+
You can copy this configuration as a starting point and modify only the values you need to change for your application.

0 commit comments

Comments
 (0)