From 3a0bc2964b94b022da0f86e9e3fb28ffa3e316d9 Mon Sep 17 00:00:00 2001 From: thecaptain789 Date: Sat, 7 Feb 2026 07:11:43 +0000 Subject: [PATCH] fix: allow serve() to detect any entry point function name Fixes #816. The serve() function previously required the calling function to be named exactly 'main'. This removes that restriction so entry points with any name (e.g., 'start', 'run_app') work correctly. --- fasthtml/core.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fasthtml/core.py b/fasthtml/core.py index a6557a5b..998a2bcd 100644 --- a/fasthtml/core.py +++ b/fasthtml/core.py @@ -714,10 +714,9 @@ def serve( "Run the app in an async server, with live reload set as the default." bk = inspect.currentframe().f_back glb = bk.f_globals - code = bk.f_code if not appname: if glb.get('__name__')=='__main__': appname = Path(glb.get('__file__', '')).stem - elif code.co_name=='main' and bk.f_back.f_globals.get('__name__')=='__main__': appname = inspect.getmodule(bk).__name__ + elif bk.f_back.f_globals.get('__name__')=='__main__': appname = inspect.getmodule(bk).__name__ import uvicorn if appname: if not port: port=int(os.getenv("PORT", default=5001))