Cat Feeder  1.0.0
The Cat feeder project
Loading...
Searching...
No Matches
core_const.py
Go to the documentation of this file.
1r"""
2# +==== BEGIN CatFeeder =================+
3# LOGO:
4# ..............(..../\
5# ...............)..(.')
6# ..............(../..)
7# ...............\‍(__)|
8# Inspired by Joan Stark
9# source https://www.asciiart.eu/
10# animals/cats
11# /STOP
12# PROJECT: CatFeeder
13# FILE: core_const.py
14# CREATION DATE: 13-01-2026
15# LAST Modified: 22:16:13 14-01-2026
16# DESCRIPTION:
17# This is the backend server in charge of making the actual website work.
18# /STOP
19# COPYRIGHT: (c) Cat Feeder
20# PURPOSE: File in charge of containing the settings for the core functionalities of the server.
21# // AR
22# +==== END CatFeeder =================+
23"""
24
25from typing import List
26from display_tty import Disp, initialise_logger
27
28from ..config import TOMLLoader, refresh_debug
29
30from ..utils import constants as CONST
31
32# toml config file
33TOML: TOMLLoader = TOMLLoader()
34
35# Refresh debug mode based on the latest configuration
36IDISP: Disp = initialise_logger("CORE Constants", refresh_debug(CONST.DEBUG))
37
38# The section where the middleware configuration is stored in the toml file
39TOML_MIDDLEWARE_SECTION = "Server_configuration.middleware."
40
41
42# Gzip optimisation parameters
43# Minimum size in bytes to apply Gzip compression
44GZIP_MINIMUM_SIZE: int = TOML.get_toml_variable(
45 f"{TOML_MIDDLEWARE_SECTION}gzip", "minimum_size", 500
46)
47
48# Compression level for Gzip (1-9)
49GZIP_COMPRESSION_LEVEL: int = TOML.get_toml_variable(
50 f"{TOML_MIDDLEWARE_SECTION}gzip", "compression_level", 9
51)
52
53# Cors parameters
54# List of allowed origins for CORS
55CORS_ALLOW_ORIGINS: List[str] = TOML.get_toml_variable(
56 f"{TOML_MIDDLEWARE_SECTION}cors", "allow_origins", ["*"]
57)
58
59# Whether to allow credentials in CORS
60CORS_ALLOW_CREDENTIALS: bool = TOML.get_toml_variable(
61 f"{TOML_MIDDLEWARE_SECTION}cors", "allow_credentials", True
62)
63
64# List of allowed HTTP methods for CORS
65CORS_ALLOW_METHODS: List[str] = TOML.get_toml_variable(
66 f"{TOML_MIDDLEWARE_SECTION}cors", "allow_methods", ["*"]
67)
68
69# List of allowed headers for CORS
70CORS_ALLOW_HEADERS: List[str] = TOML.get_toml_variable(
71 f"{TOML_MIDDLEWARE_SECTION}cors", "allow_headers", ["*"]
72)
73
74# Https redirection
75# Whether to force HTTPS redirection in production
76SERVER_PROD_FORCE_HTTPS: bool = TOML.get_toml_variable(
77 f"{TOML_MIDDLEWARE_SECTION}https", "force_https", True
78)
79
80# Trusted hosts
81TRUSTED_HOSTS_LIST: List[str] = TOML.get_toml_variable(
82 f"{TOML_MIDDLEWARE_SECTION}trusted_hosts", "host", []
83)
84
85if not SERVER_PROD_FORCE_HTTPS:
86 LOCAL_HOSTS: List[str] = TOML.get_toml_variable(
87 f"{TOML_MIDDLEWARE_SECTION}trusted_hosts", "dev_hosts",
88 ["localhost", "127.0.0.1", "::1"]
89 )
90 TRUSTED_HOSTS_LIST.extend(LOCAL_HOSTS)
91
92IDISP.log_info("Core constants loaded configurations.")
93IDISP.log_debug(f"GZIP_MINIMUM_SIZE: {GZIP_MINIMUM_SIZE}")
94IDISP.log_debug(f"GZIP_COMPRESSION_LEVEL: {GZIP_COMPRESSION_LEVEL}")
95IDISP.log_debug(f"CORS_ALLOW_ORIGINS: {CORS_ALLOW_ORIGINS}")
96IDISP.log_debug(f"CORS_ALLOW_CREDENTIALS: {CORS_ALLOW_CREDENTIALS}")
97IDISP.log_debug(f"CORS_ALLOW_METHODS: {CORS_ALLOW_METHODS}")
98IDISP.log_debug(f"CORS_ALLOW_HEADERS: {CORS_ALLOW_HEADERS}")
99IDISP.log_debug(f"SERVER_PROD_FORCE_HTTPS: {SERVER_PROD_FORCE_HTTPS}")
100IDISP.log_debug(f"TRUSTED_HOSTS_LIST: {TRUSTED_HOSTS_LIST}")