Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

tweak(platform): Disable docs endpoint when not local (#8265)

Aarushi2aed470d2610
diff --git a/autogpt_platform/backend/.env.example b/autogpt_platform/backend/.env.example
index c2204abaea..ed87d8fb75 100644
--- a/autogpt_platform/backend/.env.example
+++ b/autogpt_platform/backend/.env.example
@@ -98,3 +98,5 @@ ENABLE_CLOUD_LOGGING=false
ENABLE_FILE_LOGGING=false
# Use to manually set the log directory
# LOG_DIR=./logs
+
+APP_ENV=local
diff --git a/autogpt_platform/backend/backend/server/rest_api.py b/autogpt_platform/backend/backend/server/rest_api.py
index 4378cfb50a..99dba10009 100644
--- a/autogpt_platform/backend/backend/server/rest_api.py
+++ b/autogpt_platform/backend/backend/server/rest_api.py
@@ -51,6 +51,7 @@ class AgentServer(AppService):
await db.disconnect()
def run_service(self):
+ docs_url = "/docs" if settings.config.app_env == "local" else None
app = FastAPI(
title="AutoGPT Agent Server",
description=(
@@ -60,6 +61,7 @@ class AgentServer(AppService):
summary="AutoGPT Agent Server",
version="0.1",
lifespan=self.lifespan,
+ docs_url=docs_url,
)
if self._test_dependency_overrides:
diff --git a/autogpt_platform/backend/backend/server/ws_api.py b/autogpt_platform/backend/backend/server/ws_api.py
index 8dfc54239f..039ef718fd 100644
--- a/autogpt_platform/backend/backend/server/ws_api.py
+++ b/autogpt_platform/backend/backend/server/ws_api.py
@@ -28,6 +28,7 @@ async def lifespan(app: FastAPI):
event_queue.close()
+docs_url = "/docs" if settings.config.app_env == "local" else None
app = FastAPI(lifespan=lifespan)
event_queue = RedisEventQueue()
_connection_manager = None
diff --git a/autogpt_platform/backend/backend/util/settings.py b/autogpt_platform/backend/backend/util/settings.py
index 071f5a4c1e..06222492b3 100644
--- a/autogpt_platform/backend/backend/util/settings.py
+++ b/autogpt_platform/backend/backend/util/settings.py
@@ -1,5 +1,6 @@
import json
import os
+from enum import Enum
from typing import Any, Dict, Generic, List, Set, Tuple, Type, TypeVar
from pydantic import BaseModel, Field, PrivateAttr, field_validator
@@ -15,6 +16,12 @@ from backend.util.data import get_config_path, get_data_path, get_secrets_path
T = TypeVar("T", bound=BaseSettings)
+class AppEnvironment(str, Enum):
+ LOCAL = "local"
+ DEVELOPMENT = "dev"
+ PRODUCTION = "prod"
+
+
class UpdateTrackingModel(BaseModel, Generic[T]):
_updated_fields: Set[str] = PrivateAttr(default_factory=set)
@@ -121,6 +128,11 @@ class Config(UpdateTrackingModel["Config"], BaseSettings):
"This value is then used to generate redirect URLs for OAuth flows.",
)
+ app_env: AppEnvironment = Field(
+ default=AppEnvironment.LOCAL,
+ description="The name of the app environment.",
+ )
+
backend_cors_allow_origins: List[str] = Field(default_factory=list)
@field_validator("backend_cors_allow_origins")
diff --git a/autogpt_platform/market/.env.example b/autogpt_platform/market/.env.example
index afaed399ef..5522998fc1 100644
--- a/autogpt_platform/market/.env.example
+++ b/autogpt_platform/market/.env.example
@@ -7,4 +7,6 @@ SENTRY_DSN=https://[email protected].
ENABLE_AUTH=true
SUPABASE_JWT_SECRET=our-super-secret-jwt-token-with-at-least-32-characters-long
-BACKEND_CORS_ALLOW_ORIGINS="http://localhost:3000,http://127.0.0.1:3000"
\ No newline at end of file
+BACKEND_CORS_ALLOW_ORIGINS="http://localhost:3000,http://127.0.0.1:3000"
+
+APP_ENV=local
\ No newline at end of file
diff --git a/autogpt_platform/market/market/app.py b/autogpt_platform/market/market/app.py
index 785f3d9854..864de8cb85 100644
--- a/autogpt_platform/market/market/app.py
+++ b/autogpt_platform/market/market/app.py
@@ -49,7 +49,7 @@ async def lifespan(app: fastapi.FastAPI):
yield
await db_client.disconnect()
-
+docs_url = "/docs" if os.environ.get("APP_ENV") == "local" else None
app = fastapi.FastAPI(
title="Marketplace API",
description="AutoGPT Marketplace API is a service that allows users to share AI agents.",
@@ -57,6 +57,7 @@ app = fastapi.FastAPI(
version="0.1",
lifespan=lifespan,
root_path="/api/v1/market",
+ docs_url=docs_url,
)
app.add_middleware(fastapi.middleware.gzip.GZipMiddleware, minimum_size=1000)