diff --git a/openhands/server/listen.py b/openhands/server/listen.py index 746ad4352d..87e55c8318 100644 --- a/openhands/server/listen.py +++ b/openhands/server/listen.py @@ -6,7 +6,6 @@ with warnings.catch_warnings(): from fastapi import ( FastAPI, ) -from fastapi.staticfiles import StaticFiles import openhands.agenthub # noqa F401 (we import this to get the agents registered) from openhands.server.middleware import LocalhostCORSMiddleware, NoCacheMiddleware @@ -15,6 +14,7 @@ from openhands.server.routes.public import app as public_api_router from openhands.server.routes.restricted import AttachSessionMiddleware from openhands.server.routes.restricted import app as restricted_api_router from openhands.server.routes.websocket import app as websocket_router +from openhands.server.static import SPAStaticFiles app = FastAPI() app.add_middleware( @@ -36,14 +36,4 @@ app.middleware('http')( AttachSessionMiddleware(app, target_router=restricted_api_router) ) - -class SPAStaticFiles(StaticFiles): - async def get_response(self, path: str, scope): - try: - return await super().get_response(path, scope) - except Exception: - # FIXME: just making this HTTPException doesn't work for some reason - return await super().get_response('index.html', scope) - - app.mount('/', SPAStaticFiles(directory='./frontend/build', html=True), name='dist') diff --git a/openhands/server/static.py b/openhands/server/static.py new file mode 100644 index 0000000000..ca7eb36c9b --- /dev/null +++ b/openhands/server/static.py @@ -0,0 +1,10 @@ +from fastapi.staticfiles import StaticFiles + + +class SPAStaticFiles(StaticFiles): + async def get_response(self, path: str, scope): + try: + return await super().get_response(path, scope) + except Exception: + # FIXME: just making this HTTPException doesn't work for some reason + return await super().get_response('index.html', scope)