feat(server): Add API prefix `/api` to prevent route collisions with frontend (#7472)

- Add prefix `/api` to `APIRouter` in server.py
- Update API client in Builder
   - Update default `AGPT_SERVER_URL` in .env.template
   - Update default `baseUrl` in `AutoGPTServerAPI` constructor
pull/7480/head
Reinier van der Leer 2024-07-18 06:16:58 -06:00 committed by GitHub
parent 354e626965
commit 37b7053e14
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 3 deletions

View File

@ -1 +1 @@
AGPT_SERVER_URL=http://localhost:8000
AGPT_SERVER_URL=http://localhost:8000/api

View File

@ -7,7 +7,9 @@ export default class AutoGPTServerAPI {
private socket: WebSocket | null = null;
private messageHandlers: { [key: string]: (data: any) => void } = {};
constructor(baseUrl: string = process.env.AGPT_SERVER_URL || "http://localhost:8000") {
constructor(
baseUrl: string = process.env.AGPT_SERVER_URL || "http://localhost:8000/api"
) {
this.baseUrl = baseUrl;
this.wsUrl = `ws://${new URL(this.baseUrl).host}/ws`;
}

View File

@ -70,7 +70,7 @@ class AgentServer(AppService):
)
# Define the API routes
router = APIRouter()
router = APIRouter(prefix="/api")
router.add_api_route(
path="/blocks",
endpoint=self.get_graph_blocks, # type: ignore