mirror of
https://github.com/Casvt/MIND.git
synced 2026-04-03 03:00:22 -04:00
Create Flask app on init of Server class
This commit is contained in:
1
MIND.py
1
MIND.py
@@ -63,7 +63,6 @@ def _main(
|
||||
set_db_location(db_folder)
|
||||
|
||||
SERVER = Server()
|
||||
SERVER.create_app()
|
||||
with SERVER.app.app_context():
|
||||
StartTypeHandlers.start_timer(start_type)
|
||||
setup_db()
|
||||
|
||||
@@ -64,11 +64,16 @@ class Server(metaclass=Singleton):
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.__start_type = None
|
||||
self.app = self._create_app()
|
||||
return
|
||||
|
||||
def create_app(self) -> None:
|
||||
"""Creates an flask app instance that can be used to start a web server"""
|
||||
@staticmethod
|
||||
def _create_app() -> Flask:
|
||||
"""Creates a flask app instance that can be used to start a web server.
|
||||
|
||||
Returns:
|
||||
Flask: The instance.
|
||||
"""
|
||||
from frontend.api import admin_api, api
|
||||
from frontend.ui import render, ui
|
||||
|
||||
@@ -125,8 +130,7 @@ class Server(metaclass=Singleton):
|
||||
# Setup db handling
|
||||
app.teardown_appcontext(close_db)
|
||||
|
||||
self.app = app
|
||||
return
|
||||
return app
|
||||
|
||||
def set_url_prefix(self, url_prefix: str) -> None:
|
||||
"""Change the URL prefix of the server.
|
||||
@@ -139,7 +143,7 @@ class Server(metaclass=Singleton):
|
||||
Flask(__name__),
|
||||
{url_prefix: self.app.wsgi_app}
|
||||
)
|
||||
self.url_prefix = url_prefix
|
||||
self.__class__.url_prefix = url_prefix
|
||||
return
|
||||
|
||||
def __create_waitress_server(
|
||||
|
||||
@@ -10,11 +10,10 @@ from backend.internals.server import Server
|
||||
|
||||
ui = Blueprint('ui', __name__)
|
||||
methods = ['GET']
|
||||
SERVER = Server()
|
||||
|
||||
|
||||
def render(filename: str, **kwargs: Any) -> str:
|
||||
return render_template(filename, url_prefix=SERVER.url_prefix, **kwargs)
|
||||
return render_template(filename, url_prefix=Server.url_prefix, **kwargs)
|
||||
|
||||
|
||||
@ui.route('/manifest.json', methods=methods)
|
||||
@@ -27,14 +26,14 @@ def ui_manifest():
|
||||
"description": "MIND is a simple self hosted reminder application that can send push notifications to your device. Set the reminder and forget about it!",
|
||||
"display": "standalone",
|
||||
"orientation": "portrait-primary",
|
||||
"start_url": f"{SERVER.url_prefix}/",
|
||||
"scope": f"{SERVER.url_prefix}/",
|
||||
"id": f"{SERVER.url_prefix}/",
|
||||
"start_url": f"{Server.url_prefix}/",
|
||||
"scope": f"{Server.url_prefix}/",
|
||||
"id": f"{Server.url_prefix}/",
|
||||
"background_color": "#1b1b1b",
|
||||
"theme_color": "#6b6b6b",
|
||||
"icons": [
|
||||
{
|
||||
"src": f"{SERVER.url_prefix}/static/img/favicon.svg",
|
||||
"src": f"{Server.url_prefix}/static/img/favicon.svg",
|
||||
"type": "image/svg+xml",
|
||||
"sizes": "any"
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ from frontend.ui import ui
|
||||
class Test_MIND(unittest.TestCase):
|
||||
def test_create_app(self):
|
||||
SERVER = Server()
|
||||
SERVER.create_app()
|
||||
self.assertTrue(hasattr(SERVER, 'app'))
|
||||
app = SERVER.app
|
||||
self.assertIsInstance(app, Flask)
|
||||
|
||||
Reference in New Issue
Block a user