浏览代码

revert _api to be fastapi

Khaleel Al-Adhami 2 周之前
父节点
当前提交
ff7e9150fa
共有 1 个文件被更改,包括 10 次插入22 次删除
  1. 10 22
      reflex/app.py

+ 10 - 22
reflex/app.py

@@ -32,7 +32,6 @@ from starlette.middleware import cors
 from starlette.requests import ClientDisconnect, Request
 from starlette.requests import ClientDisconnect, Request
 from starlette.responses import JSONResponse, Response, StreamingResponse
 from starlette.responses import JSONResponse, Response, StreamingResponse
 from starlette.staticfiles import StaticFiles
 from starlette.staticfiles import StaticFiles
-from typing_extensions import deprecated
 
 
 from reflex import constants
 from reflex import constants
 from reflex.admin import AdminDash
 from reflex.admin import AdminDash
@@ -394,7 +393,7 @@ class App(MiddlewareMixin, LifespanMixin):
     _stateful_pages: dict[str, None] = dataclasses.field(default_factory=dict)
     _stateful_pages: dict[str, None] = dataclasses.field(default_factory=dict)
 
 
     # The backend API object.
     # The backend API object.
-    _api: Starlette | None = None
+    _api: FastAPI | None = None
 
 
     # The state class to use for the app.
     # The state class to use for the app.
     _state: type[BaseState] | None = None
     _state: type[BaseState] | None = None
@@ -437,26 +436,19 @@ class App(MiddlewareMixin, LifespanMixin):
         | None
         | None
     ) = None
     ) = None
 
 
-    # FastAPI app for compatibility with FastAPI.
-    _cached_fastapi_app: FastAPI | None = None
-
     @property
     @property
-    @deprecated("Use `api_transformer=your_fastapi_app` instead.")
     def api(self) -> FastAPI:
     def api(self) -> FastAPI:
         """Get the backend api.
         """Get the backend api.
 
 
         Returns:
         Returns:
             The backend api.
             The backend api.
+
+        Raises:
+            ValueError: If the app has not been initialized.
         """
         """
-        if self._cached_fastapi_app is None:
-            self._cached_fastapi_app = FastAPI()
-        console.deprecate(
-            feature_name="App.api",
-            reason="Set `api_transformer=your_fastapi_app` instead.",
-            deprecation_version="0.7.9",
-            removal_version="0.8.0",
-        )
-        return self._cached_fastapi_app
+        if self._api is None:
+            raise ValueError("The app has not been initialized.")
+        return self._api
 
 
     @property
     @property
     def event_namespace(self) -> EventNamespace | None:
     def event_namespace(self) -> EventNamespace | None:
@@ -488,7 +480,7 @@ class App(MiddlewareMixin, LifespanMixin):
             set_breakpoints(self.style.pop("breakpoints"))
             set_breakpoints(self.style.pop("breakpoints"))
 
 
         # Set up the API.
         # Set up the API.
-        self._api = Starlette(lifespan=self._run_lifespan_tasks)
+        self._api = FastAPI(lifespan=self._run_lifespan_tasks)
         App._add_cors(self._api)
         App._add_cors(self._api)
         self._add_default_endpoints()
         self._add_default_endpoints()
 
 
@@ -629,12 +621,8 @@ class App(MiddlewareMixin, LifespanMixin):
 
 
         if not self._api:
         if not self._api:
             raise ValueError("The app has not been initialized.")
             raise ValueError("The app has not been initialized.")
-        if self._cached_fastapi_app is not None:
-            asgi_app = self._cached_fastapi_app
-            asgi_app.mount("", self._api)
-            App._add_cors(asgi_app)
-        else:
-            asgi_app = self._api
+
+        asgi_app = self._api
 
 
         if self.api_transformer is not None:
         if self.api_transformer is not None:
             api_transformers: Sequence[Starlette | Callable[[ASGIApp], ASGIApp]] = (
             api_transformers: Sequence[Starlette | Callable[[ASGIApp], ASGIApp]] = (