Files
mealie/mealie/app.py
Hayden bc575ec5ae feat: auto detect first login (#2722)
* 'hide' default email and password env variables

* first login API endpoint

* run code-generators

* frontend indicators for default username and pw

* remove old env variables from docs

* fix env set variable

* remove password from tests
2023-11-15 15:24:24 +00:00

136 lines
3.7 KiB
Python

import uvicorn
from fastapi import FastAPI
from fastapi.middleware.gzip import GZipMiddleware
from fastapi.routing import APIRoute
from mealie.core.config import get_app_settings
from mealie.core.root_logger import get_logger
from mealie.core.settings.static import APP_VERSION
from mealie.routes import router, spa, utility_routes
from mealie.routes.handlers import register_debug_handler
from mealie.routes.media import media_router
from mealie.services.scheduler import SchedulerRegistry, SchedulerService, tasks
settings = get_app_settings()
description = f"""
Mealie is a web application for managing your recipes, meal plans, and shopping lists. This is the Restful
API interactive documentation that can be used to explore the API. If you're justing getting started with
the API and want to get started quickly, you can use the
[API Usage | Mealie Docs](https://nightly.mealie.io/documentation/getting-started/api-usage/)
as a reference for how to get started.
As of this release <b>{APP_VERSION}</b>, Mealie is still in rapid development and therefore some of these APIs may
change from version to version.
If you have any questions or comments about mealie, please use the discord server to talk to the developers or other
community members. If you'd like to file an issue, please use the
[GitHub Issue Tracker | Mealie](https://github.com/mealie-recipes/mealie/issues/new/choose)
## Helpful Links
- [Home Page](https://mealie.io)
- [Documentation](https://nightly.mealie.io)
- [Discord](https://discord.gg/QuStdQGSGK)
- [Demo](https://demo.mealie.io)
- [Beta](https://demo.mealie.io)
"""
app = FastAPI(
title="Mealie",
description=description,
version=APP_VERSION,
docs_url=settings.DOCS_URL,
redoc_url=settings.REDOC_URL,
)
app.add_middleware(GZipMiddleware, minimum_size=1000)
register_debug_handler(app)
async def start_scheduler():
SchedulerRegistry.register_daily(
tasks.purge_group_registration,
tasks.purge_password_reset_tokens,
tasks.purge_group_data_exports,
tasks.create_mealplan_timeline_events,
tasks.delete_old_checked_list_items,
)
SchedulerRegistry.register_minutely(
tasks.post_group_webhooks,
)
SchedulerRegistry.register_hourly(
tasks.locked_user_reset,
)
SchedulerRegistry.print_jobs()
await SchedulerService.start()
def api_routers():
app.include_router(router)
app.include_router(media_router)
app.include_router(utility_routes.router)
if settings.PRODUCTION and not settings.TESTING:
spa.mount_spa(app)
api_routers()
# fix routes that would get their tags duplicated by use of @controller,
# leading to duplicate definitions in the openapi spec
for route in app.routes:
if isinstance(route, APIRoute):
route.tags = list(set(route.tags))
@app.on_event("startup")
async def system_startup():
logger = get_logger()
await start_scheduler()
logger.info("-----SYSTEM STARTUP----- \n")
logger.info("------APP SETTINGS------")
logger.info(
settings.json(
indent=4,
exclude={
"SECRET",
"SFTP_PASSWORD",
"SFTP_USERNAME",
"DB_URL", # replace by DB_URL_PUBLIC for logs
"DB_PROVIDER",
"SMTP_USER",
"SMTP_PASSWORD",
},
)
)
def main():
uvicorn.run(
"app:app",
host="0.0.0.0",
port=settings.API_PORT,
reload=True,
reload_dirs=["mealie"],
reload_delay=2,
log_level="info",
use_colors=True,
log_config=None,
workers=1,
forwarded_allow_ips="*",
)
if __name__ == "__main__":
main()