|
@@ -46,7 +46,7 @@ from reflex.components.core.client_side_routing import (
|
|
Default404Page,
|
|
Default404Page,
|
|
wait_for_client_redirect,
|
|
wait_for_client_redirect,
|
|
)
|
|
)
|
|
-from reflex.components.core.upload import UploadFilesProvider
|
|
|
|
|
|
+from reflex.components.core.upload import Upload
|
|
from reflex.components.radix import themes
|
|
from reflex.components.radix import themes
|
|
from reflex.config import get_config
|
|
from reflex.config import get_config
|
|
from reflex.event import Event, EventHandler, EventSpec
|
|
from reflex.event import Event, EventHandler, EventSpec
|
|
@@ -185,6 +185,7 @@ class App(Base):
|
|
# Set up the API.
|
|
# Set up the API.
|
|
self.api = FastAPI()
|
|
self.api = FastAPI()
|
|
self.add_cors()
|
|
self.add_cors()
|
|
|
|
+ self.add_default_endpoints()
|
|
|
|
|
|
if self.state:
|
|
if self.state:
|
|
# Set up the state manager.
|
|
# Set up the state manager.
|
|
@@ -241,12 +242,14 @@ class App(Base):
|
|
return self.api
|
|
return self.api
|
|
|
|
|
|
def add_default_endpoints(self):
|
|
def add_default_endpoints(self):
|
|
- """Add the default endpoints."""
|
|
|
|
|
|
+ """Add default api endpoints (ping)."""
|
|
# To test the server.
|
|
# To test the server.
|
|
self.api.get(str(constants.Endpoint.PING))(ping)
|
|
self.api.get(str(constants.Endpoint.PING))(ping)
|
|
|
|
|
|
|
|
+ def add_optional_endpoints(self):
|
|
|
|
+ """Add optional api endpoints (_upload)."""
|
|
# To upload files.
|
|
# To upload files.
|
|
- if UploadFilesProvider.is_used:
|
|
|
|
|
|
+ if Upload.is_used:
|
|
self.api.post(str(constants.Endpoint.UPLOAD))(upload(self))
|
|
self.api.post(str(constants.Endpoint.UPLOAD))(upload(self))
|
|
|
|
|
|
def add_cors(self):
|
|
def add_cors(self):
|
|
@@ -655,6 +658,9 @@ class App(Base):
|
|
if constants.Page404.SLUG not in self.pages:
|
|
if constants.Page404.SLUG not in self.pages:
|
|
self.add_custom_404_page()
|
|
self.add_custom_404_page()
|
|
|
|
|
|
|
|
+ # Add the optional endpoints (_upload)
|
|
|
|
+ self.add_optional_endpoints()
|
|
|
|
+
|
|
if not self._should_compile():
|
|
if not self._should_compile():
|
|
return
|
|
return
|
|
|
|
|
|
@@ -824,8 +830,6 @@ class App(Base):
|
|
for output_path, code in compile_results:
|
|
for output_path, code in compile_results:
|
|
compiler_utils.write_page(output_path, code)
|
|
compiler_utils.write_page(output_path, code)
|
|
|
|
|
|
- self.add_default_endpoints()
|
|
|
|
-
|
|
|
|
@contextlib.asynccontextmanager
|
|
@contextlib.asynccontextmanager
|
|
async def modify_state(self, token: str) -> AsyncIterator[BaseState]:
|
|
async def modify_state(self, token: str) -> AsyncIterator[BaseState]:
|
|
"""Modify the state out of band.
|
|
"""Modify the state out of band.
|