-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
93 lines (70 loc) · 3.12 KB
/
config.py
File metadata and controls
93 lines (70 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""
Application Configurations
Default Ellar Configurations are exposed here through `ConfigDefaultTypesMixin`
Make changes and define your own configurations specific to your application
export ELLAR_CONFIG_MODULE=db_learning.config:DevelopmentConfig
"""
import typing as t
from ellar.common import IExceptionHandler, JSONResponse
from ellar.core import ConfigDefaultTypesMixin
from ellar.core.versioning import BaseAPIVersioning, DefaultAPIVersioning
from ellar.pydantic import ENCODERS_BY_TYPE as encoders_by_type
from starlette.middleware import Middleware
class BaseConfig(ConfigDefaultTypesMixin):
DEBUG: bool = False
DEFAULT_JSON_CLASS: t.Type[JSONResponse] = JSONResponse
SECRET_KEY: str = "ellar_QdZwHTfLkZQWQtAot-V6gbTHONMn3ekrl5jdcb5AOC8"
# injector auto_bind = True allows you to resolve types that are not registered on the container
# For more info, read: https://injector.readthedocs.io/en/latest/index.html
INJECTOR_AUTO_BIND = False
# jinja Environment options
# https://jinja.palletsprojects.com/en/3.0.x/api/#high-level-api
JINJA_TEMPLATES_OPTIONS: t.Dict[str, t.Any] = {}
# Application route versioning scheme
VERSIONING_SCHEME: BaseAPIVersioning = DefaultAPIVersioning()
# Enable or Disable Application Router route searching by appending backslash
REDIRECT_SLASHES: bool = False
# Define references to static folders in python packages.
# eg STATIC_FOLDER_PACKAGES = [('boostrap4', 'statics')]
STATIC_FOLDER_PACKAGES: t.Optional[t.List[t.Union[str, t.Tuple[str, str]]]] = []
# Define references to static folders defined within the project
STATIC_DIRECTORIES: t.Optional[t.List[t.Union[str, t.Any]]] = []
# static route path
STATIC_MOUNT_PATH: str = "/static"
CORS_ALLOW_ORIGINS: t.List[str] = ["*"]
CORS_ALLOW_METHODS: t.List[str] = ["*"]
CORS_ALLOW_HEADERS: t.List[str] = ["*"]
ALLOWED_HOSTS: t.List[str] = ["*"]
# Application middlewares
MIDDLEWARE: t.Sequence[Middleware] = []
# A dictionary mapping either integer status codes,
# or exception class types onto callables which handle the exceptions.
# Exception handler callables should be of the form
# `handler(context:IExecutionContext, exc: Exception) -> response`
# and may be either standard functions, or async functions.
EXCEPTION_HANDLERS: t.List[IExceptionHandler] = []
# Object Serializer custom encoders
SERIALIZER_CUSTOM_ENCODER: t.Dict[t.Any, t.Callable[[t.Any], t.Any]] = (
encoders_by_type
)
class DevelopmentConfig(BaseConfig):
DEBUG: bool = True
ELLAR_SQL: t.Dict[str, t.Any] = {
"databases": {
"default": "sqlite:///app.db",
},
"echo": True,
"migration_options": {
"directory": "migrations" # root directory will be determined based on where the module is instantiated.
},
"models": ["db_learning.models"],
}
class TestConfig(BaseConfig):
DEBUG = False
ELLAR_SQL: t.Dict[str, t.Any] = {
**DevelopmentConfig.ELLAR_SQL,
"databases": {
"default": "sqlite:///test.db",
},
"echo": False,
}