get admin settings at startup

This commit is contained in:
Tiago vasconcelos 2022-03-12 14:23:53 +00:00 committed by dni ⚡
parent b47ed30681
commit 4bf17c5df2

View File

@ -18,6 +18,7 @@ from loguru import logger
import lnbits.settings
from lnbits.core.tasks import register_task_listeners
from .commands import get_admin_settings
from .core import core_app
from .core.views.generic import core_html_routes
from .helpers import (
@ -42,6 +43,7 @@ def create_app(config_object="lnbits.settings") -> FastAPI:
"""Create application factory.
:param config_object: The configuration object to use.
"""
<<<<<<< HEAD
configure_logger()
app = FastAPI(
@ -53,6 +55,14 @@ def create_app(config_object="lnbits.settings") -> FastAPI:
},
)
app.mount("/static", StaticFiles(packages=[("lnbits", "static")]), name="static")
=======
app = FastAPI()
if lnbits.settings.LNBITS_ADMIN_UI:
check_settings(app)
app.mount("/static", StaticFiles(directory="lnbits/static"), name="static")
>>>>>>> e3a1b3ae (get admin settings at startup)
app.mount(
"/core/static",
StaticFiles(packages=[("lnbits.core", "static")]),
@ -64,7 +74,6 @@ def create_app(config_object="lnbits.settings") -> FastAPI:
app.add_middleware(
CORSMiddleware, allow_origins=origins, allow_methods=["*"], allow_headers=["*"]
)
g().config = lnbits.settings
g().base_url = f"http://{lnbits.settings.HOST}:{lnbits.settings.PORT}"
@ -101,6 +110,18 @@ def create_app(config_object="lnbits.settings") -> FastAPI:
return app
def check_settings(app: FastAPI):
@app.on_event("startup")
async def check_settings_admin():
while True:
admin_set = await get_admin_settings()
if admin_set :
break
print("ERROR:", admin_set)
await asyncio.sleep(5)
# admin_set = await get_admin_settings()
g().admin_conf = admin_set
def check_funding_source(app: FastAPI) -> None:
@app.on_event("startup")
async def check_wallet_status():