From 77bae7c0c653e14ff787bc24edcc12518db6cc00 Mon Sep 17 00:00:00 2001 From: Shrikant Sharat Kandula Date: Fri, 15 Nov 2024 13:34:35 +0530 Subject: [PATCH] chore: Don't break when Appsmtih API URL isn't set (#37309) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We actually don't need the `APPSMITH_API_BASE_URL` variable to be varying in production ever at all, and the `routes.ts` file already does have a default for this (on EE). Let's just use that instead of throwing an impact-less error. Ideally though, we shouldn't have this env variable at all. Less things that are configurable, less things that can break other things. ## Automation /test sanity ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: f049d468998530cddd9f7ad45542790c9e12241b > Cypress dashboard. > Tags: `@tag.Sanity` > Spec: >
Wed, 13 Nov 2024 07:41:57 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No ## Summary by CodeRabbit ## Release Notes - **New Features** - Introduced constants for API URLs to streamline endpoint configurations. - **Bug Fixes** - Updated API request URLs to use new constants, ensuring consistency across the application. - **Refactor** - Centralized route constants to improve maintainability. - Renamed entities in test cases for clarity while preserving functionality. - **Chores** - Removed obsolete environment variable related to API base URL from the Docker configuration. --- app/client/packages/rts/src/constants/routes.ts | 9 +++++++++ .../packages/rts/src/middlewares/socket-auth.ts | 4 ++-- app/client/packages/rts/src/server.ts | 11 +---------- app/client/packages/rts/src/test/server.test.ts | 3 ++- deploy/docker/fs/opt/appsmith/templates/docker.env.sh | 1 - 5 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 app/client/packages/rts/src/constants/routes.ts diff --git a/app/client/packages/rts/src/constants/routes.ts b/app/client/packages/rts/src/constants/routes.ts new file mode 100644 index 0000000000..d6f275c956 --- /dev/null +++ b/app/client/packages/rts/src/constants/routes.ts @@ -0,0 +1,9 @@ +const BASE_API_URL = "http://localhost:8091"; + +export const RTS_BASE_PATH = "/rts"; +export const RTS_BASE_API_PATH = "/rts-api/v1"; +export const RTS_BASE_API_URL = `${BASE_API_URL}${RTS_BASE_API_PATH}`; + +export const BASE_APPSMITH_API_URL = + process.env.APPSMITH_API_BASE_URL || "http://localhost:8080/api/v1"; +export const INTERNAL_BASE_URL = "http://localhost:8080/internal/v1"; diff --git a/app/client/packages/rts/src/middlewares/socket-auth.ts b/app/client/packages/rts/src/middlewares/socket-auth.ts index 5f2a8f545c..353a908f9c 100644 --- a/app/client/packages/rts/src/middlewares/socket-auth.ts +++ b/app/client/packages/rts/src/middlewares/socket-auth.ts @@ -2,7 +2,7 @@ import type { Socket } from "socket.io"; import log from "loglevel"; import axios from "axios"; -const API_BASE_URL = process.env.APPSMITH_API_BASE_URL; +import { BASE_APPSMITH_API_URL } from "@constants/routes"; export async function tryAuth(socket: Socket) { /* ********************************************************* */ @@ -35,7 +35,7 @@ export async function tryAuth(socket: Socket) { try { response = await axios.request({ method: "GET", - url: API_BASE_URL + "/users/me", + url: BASE_APPSMITH_API_URL + "/users/me", headers: { Cookie: sessionCookie, }, diff --git a/app/client/packages/rts/src/server.ts b/app/client/packages/rts/src/server.ts index b4d77949d4..98c4fdac34 100644 --- a/app/client/packages/rts/src/server.ts +++ b/app/client/packages/rts/src/server.ts @@ -12,9 +12,7 @@ import ast_routes from "./routes/ast_routes"; import dsl_routes from "./routes/dsl_routes"; import health_check_routes from "./routes/health_check_routes"; -const RTS_BASE_PATH = "/rts"; - -export const RTS_BASE_API_PATH = "/rts-api/v1"; +import { RTS_BASE_PATH, RTS_BASE_API_PATH } from "@constants/routes"; // Setting the logLevel for all log messages const logLevel: LogLevelDesc = (process.env.APPSMITH_LOG_LEVEL || @@ -22,13 +20,6 @@ const logLevel: LogLevelDesc = (process.env.APPSMITH_LOG_LEVEL || log.setLevel(logLevel); -const API_BASE_URL = process.env.APPSMITH_API_BASE_URL; - -if (API_BASE_URL == null || API_BASE_URL === "") { - log.error("Please provide a valid value for `APPSMITH_API_BASE_URL`."); - process.exit(1); -} - const APPSMITH_RTS_PORT = process.env.APPSMITH_RTS_PORT || 8091; //Disable x-powered-by header to prevent information disclosure diff --git a/app/client/packages/rts/src/test/server.test.ts b/app/client/packages/rts/src/test/server.test.ts index 65ec4b03d6..2088884f89 100644 --- a/app/client/packages/rts/src/test/server.test.ts +++ b/app/client/packages/rts/src/test/server.test.ts @@ -1,4 +1,5 @@ -import app, { RTS_BASE_API_PATH } from "../server"; +import app from "../server"; +import { RTS_BASE_API_PATH } from "@constants/routes"; import supertest from "supertest"; const singleScript = { diff --git a/deploy/docker/fs/opt/appsmith/templates/docker.env.sh b/deploy/docker/fs/opt/appsmith/templates/docker.env.sh index 9a826d4dfb..d183f24767 100644 --- a/deploy/docker/fs/opt/appsmith/templates/docker.env.sh +++ b/deploy/docker/fs/opt/appsmith/templates/docker.env.sh @@ -67,7 +67,6 @@ APPSMITH_DB_URL=mongodb://$MONGO_USER:$DB_PASSWORD@localhost:27017/appsmith APPSMITH_POSTGRES_DB_URL=postgresql://appsmith:$DB_PASSWORD@localhost:5432/appsmith APPSMITH_MONGODB_USER=$MONGO_USER APPSMITH_MONGODB_PASSWORD=$DB_PASSWORD -APPSMITH_API_BASE_URL=http://localhost:8080/api/v1 APPSMITH_REDIS_URL=redis://127.0.0.1:6379