2# +==== BEGIN CatFeeder =================+
5# ...............)..(.')
7# ...............\(__)|
8# Inspired by Joan Stark
9# source https://www.asciiart.eu/
14# CREATION DATE: 19-11-2025
15# LAST Modified: 0:15:46 25-01-2026
17# This is the backend server in charge of making the actual website work.
19# COPYRIGHT: (c) Cat Feeder
20# PURPOSE: The endpoints that can be considered as bonus in the server.
22# +==== END CatFeeder =================+
26from display_tty
import Disp, initialise_logger
27from fastapi
import Request, Response
28from ...core
import RuntimeControl, RuntimeManager, RI
29from ...crons
import BackgroundTasks
30from ...server_header
import ServerHeaders
31from ...utils
import constants
as CONST
32from ...http_codes
import HCI, HttpDataTypes, HTTP_DEFAULT_TYPE
33from ...boilerplates
import BoilerplateIncoming, BoilerplateResponses, BoilerplateNonHTTP
40 disp: Disp = initialise_logger(__qualname__,
False)
42 def __init__(self, success: int = 0, error: int = 84, debug: bool =
False) ->
None:
46 runtime_data (RuntimeData): _description_
47 success (int, optional): _description_. Defaults to 0.
48 error (int, optional): _description_. Defaults to 84.
49 debug (bool, optional): _description_. Defaults to False.
52 self.
disp.update_disp_debug(debug)
53 self.
disp.log_debug(
"Initialising...")
72 self.
disp.log_debug(
"Initialised")
76 The endpoint corresponding to ''.
79 Response: _description_: The data to send back to the user as a response.
86 message=
"Welcome to the cat_feeder server.",
91 self.
disp.log_debug(f
"sent body : {body}", title)
93 f
"header = {self.server_headers_initialised.for_json()}", title
95 outgoing = HCI.success(
97 content_type=HTTP_DEFAULT_TYPE,
100 self.
disp.log_debug(f
"ready_to_go: {outgoing}", title)
103 async def get_root(self, request: Request) -> Response:
105 The endpoint corresponding to '/'.
108 Response: _description_: The data to send back to the user as a response.
115 message=
"Welcome to the cat_feeder server.",
120 self.
disp.log_debug(f
"sent body : {body}", title)
122 f
"header = {self.server_headers_initialised.for_json()}", title
124 outgoing = HCI.success(
126 content_type=HTTP_DEFAULT_TYPE,
129 self.
disp.log_debug(f
"ready_to_go: {outgoing}", title)
134 The endpoint corresponding to '/'.
137 Response: _description_: The data to send back to the user as a response.
144 message=
"Welcome to the cat_feeder server.",
149 self.
disp.log_debug(f
"sent body : {body}", title)
151 f
"header = {self.server_headers_initialised.for_json()}", title
153 outgoing = HCI.success(
155 content_type=HTTP_DEFAULT_TYPE,
158 self.
disp.log_debug(f
"ready_to_go: {outgoing}", title)
162 """The endpoint to respond to the typical GET /favicon.ico path.
165 request (Request): The potential arguments passed in the emitted request.
168 Response: The response to the emmiter.
170 icon = CONST.ICON_PATH
171 self.
disp.log_debug(f
"Favicon path: {icon}")
172 if os.path.isfile(icon):
173 return HCI.success(icon, content_type=HttpDataTypes.XICON)
174 return HCI.not_found(
"Icon not found in the expected directory", content_type=HttpDataTypes.TEXT)
177 """The endpoint to respond to the typical GET /static/logo.png path.
180 request (Request): The potential arguments passed in the emitted request.
183 Response: The response to the emmiter.
185 icon = CONST.PNG_ICON_PATH
186 self.
disp.log_debug(f
"Static logo path: {icon}")
187 if os.path.isfile(icon):
188 return HCI.success(icon, content_type=HttpDataTypes.PNG)
189 return HCI.not_found(
"Icon not found in the expected directory", content_type=HttpDataTypes.TEXT)
193 The endpoint allowing a user to stop the server.
196 Response: _description_: The data to send back to the user as a response.
198 title =
"Stop server"
204 "Unauthenticated user tried to stop the server."
209 "Non-admin user tried to stop the server.", title
213 message=
"You do not have enough privileges to run this endpoint.",
214 resp=
"privilege to low",
221 message=
"The server is stopping",
226 self.
disp.log_debug(
"Server shutting down...", f
"{title}")
231 msg =
"The server is stopping with errors, cron exited "
232 msg += f
"with {status}."
245 return HCI.internal_server_error(content=body, content_type=HTTP_DEFAULT_TYPE, headers=self.
server_headers_initialised.for_json())
249 """Health check endpoint for container orchestration and monitoring.
251 Returns a simple 200 OK response to indicate the service is alive and responding.
252 Used by Docker healthchecks, Kubernetes probes, load balancers, etc.
255 request (Request): The incoming HTTP request.
258 Response: HTTP 200 with status message.
261 title=
"Health Check",
262 message=
"Service is healthy",
269 content_type=HTTP_DEFAULT_TYPE,
275 """Root GET beacon endpoint."""
279 """Root POST beacon endpoint."""
283 """Root PUT beacon endpoint."""
287 """Root PATCH beacon endpoint."""
291 """Root DELETE beacon endpoint."""
295 """Root HEAD beacon endpoint."""
299 """Root OPTIONS beacon endpoint."""
304 """Home GET beacon endpoint."""
308 """Home POST beacon endpoint."""
312 """Home PUT beacon endpoint."""
316 """Home PATCH beacon endpoint."""
320 """Home DELETE beacon endpoint."""
324 """Home HEAD beacon endpoint."""
328 """Home OPTIONS beacon endpoint."""
333 """API v1 GET beacon endpoint."""
337 """API v1 POST beacon endpoint."""
341 """API v1 PUT beacon endpoint."""
345 """API v1 PATCH beacon endpoint."""
349 """API v1 DELETE beacon endpoint."""
353 """API v1 HEAD beacon endpoint."""
357 """API v1 OPTIONS beacon endpoint."""
BoilerplateIncoming boilerplate_incoming_initialised
Response get_root(self, Request request)
Response api_v1_beacon_head(self, Request request)
Response get_static_logo(self, Request request)
Response api_v1_beacon_patch(self, Request request)
RuntimeControl runtime_controls_initialised
Response root_beacon_get(self, Request request)
Response home_beacon_put(self, Request request)
BackgroundTasks background_tasks_initialised
Response api_v1_beacon_delete(self, Request request)
RuntimeManager runtime_manager
None __init__(self, int success=0, int error=84, bool debug=False)
Response home_beacon_patch(self, Request request)
Response api_v1_beacon_put(self, Request request)
Response get_welcome(self, Request request)
Response home_beacon_post(self, Request request)
Response home_beacon_options(self, Request request)
Response get_api_v1(self, Request request)
ServerHeaders server_headers_initialised
Response post_stop_server(self, Request request)
Response root_beacon_head(self, Request request)
Response api_v1_beacon_get(self, Request request)
Response api_v1_beacon_options(self, Request request)
Response root_beacon_delete(self, Request request)
Response home_beacon_get(self, Request request)
Response root_beacon_patch(self, Request request)
Response root_beacon_put(self, Request request)
Response home_beacon_head(self, Request request)
BoilerplateResponses boilerplate_responses_initialised
Response root_beacon_options(self, Request request)
Response get_health(self, Request request)
Response api_v1_beacon_post(self, Request request)
BoilerplateNonHTTP boilerplate_non_http_initialised
Response home_beacon_delete(self, Request request)
Response root_beacon_post(self, Request request)
Response get_favicon(self, Request request)