Initial Structure
This commit is contained in:
0
src/__init__.py
Normal file
0
src/__init__.py
Normal file
0
src/config/__init__.py
Normal file
0
src/config/__init__.py
Normal file
0
src/rendering/__init__.py
Normal file
0
src/rendering/__init__.py
Normal file
3
src/routes/__init__.py
Normal file
3
src/routes/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
|
3
src/routes/routes.py
Normal file
3
src/routes/routes.py
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
def default_route(path: str):
|
||||
return f"Default route for {path}"
|
0
src/server/__init__.py
Normal file
0
src/server/__init__.py
Normal file
28
src/server/server.py
Normal file
28
src/server/server.py
Normal file
@ -0,0 +1,28 @@
|
||||
from flask import Flask
|
||||
from typing import Callable, Dict
|
||||
|
||||
|
||||
class Server:
|
||||
def __init__(
|
||||
self,
|
||||
debug: bool = True,
|
||||
host: str = "0.0.0.0",
|
||||
port: int = 8080,
|
||||
template_functions: Dict[str, Callable] = {},
|
||||
):
|
||||
self.debug = debug
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.app = Flask(__name__)
|
||||
for name, func in template_functions.items():
|
||||
self.register_template_function(name, func)
|
||||
|
||||
def run(self):
|
||||
self.app.debug = self.debug
|
||||
self.app.run(host=self.host, port=self.port)
|
||||
|
||||
def register_template_function(self, name, func):
|
||||
self.app.jinja_env.globals.update({name: func})
|
||||
|
||||
def register_route(self, route, func, defaults=None):
|
||||
self.app.add_url_rule(route, func.__name__, func, defaults=defaults)
|
Reference in New Issue
Block a user