add second FastAPI server for static site
This commit is contained in:
@@ -23,6 +23,9 @@ with warnings.catch_warnings():
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.responses import FileResponse
|
||||
|
||||
|
||||
from pymobiledevice3.services.dvt.instruments.location_simulation_base import (
|
||||
LocationSimulationBase,
|
||||
@@ -131,7 +134,7 @@ class TunneldRunnerSio:
|
||||
usbmux_monitor: bool = True,
|
||||
mobdev2_monitor: bool = True,
|
||||
) -> None:
|
||||
cls(
|
||||
instance = cls(
|
||||
host,
|
||||
port,
|
||||
protocol=protocol,
|
||||
@@ -139,8 +142,8 @@ class TunneldRunnerSio:
|
||||
wifi_monitor=wifi_monitor,
|
||||
usbmux_monitor=usbmux_monitor,
|
||||
mobdev2_monitor=mobdev2_monitor,
|
||||
context=context,
|
||||
)._run_app()
|
||||
context=context,)
|
||||
asyncio.run(instance._run_app())
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -173,12 +176,13 @@ class TunneldRunnerSio:
|
||||
"127.0.0.1" if host in ("0.0.0.0", "::") else host,
|
||||
port,
|
||||
)
|
||||
self._vue_app = FastAPI()
|
||||
self._app = FastAPI(
|
||||
title="iOS Device Management API",
|
||||
lifespan=lifespan,
|
||||
cors_allowed_origins="*",
|
||||
)
|
||||
self._asgi_app = socketio.ASGIApp(self.context.sio, self._app)
|
||||
self._asgi_app = socketio.ASGIApp(self.context.sio, self._vue_app)
|
||||
self.context.icloud_monitor.sio = self.context.sio
|
||||
self.context.icloud_monitor.get_client_sids = lambda: list(
|
||||
self.context.connected_clients
|
||||
@@ -190,7 +194,6 @@ class TunneldRunnerSio:
|
||||
usbmux_monitor=usbmux_monitor,
|
||||
mobdev2_monitor=mobdev2_monitor,
|
||||
)
|
||||
|
||||
async def get_tun(
|
||||
udid: Optional[str] = None, max_retries: int = 10, retry_delay: float = 0.5
|
||||
) -> RemoteServiceDiscoveryService:
|
||||
@@ -1590,10 +1593,21 @@ class TunneldRunnerSio:
|
||||
"message": f"Unknown operation: {command}",
|
||||
}
|
||||
|
||||
def _run_app(self) -> None:
|
||||
uvicorn.run(
|
||||
self._asgi_app, host=self.host, port=self.port, loop="asyncio", workers=1
|
||||
)
|
||||
|
||||
self._vue_app.mount("/assets", StaticFiles(directory="../../front-end/dist/spa/assets", html=True), name="vue")
|
||||
@self._vue_app.get("/{full_path:path}")
|
||||
async def serve_vue_app(full_path: str):
|
||||
return FileResponse("../../front-end/dist/spa/index.html")
|
||||
|
||||
|
||||
async def _run_app(self) -> None:
|
||||
api = uvicorn.Server(uvicorn.Config(self._app, host=self.host, port=49151, log_level="info"))
|
||||
vue = uvicorn.Server(uvicorn.Config(self._asgi_app, host=self.host, port=8087, log_level="info"))
|
||||
await asyncio.gather(api.serve(), vue.serve())
|
||||
|
||||
# uvicorn.run(
|
||||
# self._asgi_app, host=self.host, port=self.port, loop="asyncio", workers=1
|
||||
# )
|
||||
|
||||
|
||||
class LocationSimulationQueue(LocationSimulation):
|
||||
|
||||
Reference in New Issue
Block a user