From b3cbc160eb94025402b5a0ef21653c207bbe8ccd Mon Sep 17 00:00:00 2001 From: Stevche Radevski Date: Wed, 6 Nov 2024 15:08:38 +0100 Subject: [PATCH] fix: Default to a relative path for the admin backend URL (#9947) --- .changeset/tough-spiders-admire.md | 8 ++++++++ packages/admin/dashboard/src/lib/client/client.ts | 2 +- packages/admin/dashboard/src/lib/query-client.ts | 2 +- packages/core/framework/src/config/types.ts | 2 +- packages/core/types/src/common/config-module.ts | 2 +- .../utils/src/common/__tests__/define-config.spec.ts | 12 ++++++------ packages/core/utils/src/common/define-config.ts | 2 +- 7 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 .changeset/tough-spiders-admire.md diff --git a/.changeset/tough-spiders-admire.md b/.changeset/tough-spiders-admire.md new file mode 100644 index 0000000000..5e58a608ec --- /dev/null +++ b/.changeset/tough-spiders-admire.md @@ -0,0 +1,8 @@ +--- +"@medusajs/dashboard": patch +"@medusajs/framework": patch +"@medusajs/types": patch +"@medusajs/utils": patch +--- + +fix: Default to a relative path for backend URL in admin diff --git a/packages/admin/dashboard/src/lib/client/client.ts b/packages/admin/dashboard/src/lib/client/client.ts index d587805978..d3ba815841 100644 --- a/packages/admin/dashboard/src/lib/client/client.ts +++ b/packages/admin/dashboard/src/lib/client/client.ts @@ -1,6 +1,6 @@ import Medusa from "@medusajs/js-sdk" -export const backendUrl = __BACKEND_URL__ ?? "http://localhost:9000" +export const backendUrl = __BACKEND_URL__ ?? "/" export const sdk = new Medusa({ baseUrl: backendUrl, diff --git a/packages/admin/dashboard/src/lib/query-client.ts b/packages/admin/dashboard/src/lib/query-client.ts index 646ea1e449..faa731e945 100644 --- a/packages/admin/dashboard/src/lib/query-client.ts +++ b/packages/admin/dashboard/src/lib/query-client.ts @@ -1,6 +1,6 @@ import { QueryClient } from "@tanstack/react-query" -export const MEDUSA_BACKEND_URL = __BACKEND_URL__ ?? "http://localhost:9000" +export const MEDUSA_BACKEND_URL = __BACKEND_URL__ ?? "/" export const queryClient = new QueryClient({ defaultOptions: { diff --git a/packages/core/framework/src/config/types.ts b/packages/core/framework/src/config/types.ts index 528e62affe..052bf98ac3 100644 --- a/packages/core/framework/src/config/types.ts +++ b/packages/core/framework/src/config/types.ts @@ -72,7 +72,7 @@ export type AdminOptions = { */ outDir?: string /** - * The URL of your Medusa application. This is useful to set when you deploy the Medusa application. + * The URL of your Medusa application. Defaults to the browser origin. This is useful to set when running the admin on a separate domain. * * @example * ```ts title="medusa-config.ts" diff --git a/packages/core/types/src/common/config-module.ts b/packages/core/types/src/common/config-module.ts index d2e45ee31d..92787f603f 100644 --- a/packages/core/types/src/common/config-module.ts +++ b/packages/core/types/src/common/config-module.ts @@ -50,7 +50,7 @@ export interface AdminOptions { */ path: `/${string}` /** - * The URL of your Medusa application. This is useful to set when you deploy the Medusa application. + * The URL of your Medusa application. Defaults to the browser origin. This is useful to set when running the admin on a separate domain. * * @example * ```js title="medusa-config.js" diff --git a/packages/core/utils/src/common/__tests__/define-config.spec.ts b/packages/core/utils/src/common/__tests__/define-config.spec.ts index 0742378b52..9919e3e6b9 100644 --- a/packages/core/utils/src/common/__tests__/define-config.spec.ts +++ b/packages/core/utils/src/common/__tests__/define-config.spec.ts @@ -6,7 +6,7 @@ describe("defineConfig", function () { expect(defineConfig()).toMatchInlineSnapshot(` { "admin": { - "backendUrl": "http://localhost:9000", + "backendUrl": "/", "path": "/app", }, "featureFlags": {}, @@ -159,7 +159,7 @@ describe("defineConfig", function () { ).toMatchInlineSnapshot(` { "admin": { - "backendUrl": "http://localhost:9000", + "backendUrl": "/", "path": "/app", }, "featureFlags": {}, @@ -318,7 +318,7 @@ describe("defineConfig", function () { ).toMatchInlineSnapshot(` { "admin": { - "backendUrl": "http://localhost:9000", + "backendUrl": "/", "path": "/app", }, "featureFlags": {}, @@ -483,7 +483,7 @@ describe("defineConfig", function () { ).toMatchInlineSnapshot(` { "admin": { - "backendUrl": "http://localhost:9000", + "backendUrl": "/", "path": "/app", }, "featureFlags": {}, @@ -644,7 +644,7 @@ describe("defineConfig", function () { ).toMatchInlineSnapshot(` { "admin": { - "backendUrl": "http://localhost:9000", + "backendUrl": "/", "path": "/app", }, "featureFlags": {}, @@ -800,7 +800,7 @@ describe("defineConfig", function () { ).toMatchInlineSnapshot(` { "admin": { - "backendUrl": "http://localhost:9000", + "backendUrl": "/", "path": "/app", }, "featureFlags": {}, diff --git a/packages/core/utils/src/common/define-config.ts b/packages/core/utils/src/common/define-config.ts index 1e3065ea4d..25fe76a992 100644 --- a/packages/core/utils/src/common/define-config.ts +++ b/packages/core/utils/src/common/define-config.ts @@ -14,7 +14,7 @@ import { normalizeImportPathWithSource } from "./normalize-import-path-with-sour import { resolveExports } from "./resolve-exports" const DEFAULT_SECRET = "supersecret" -const DEFAULT_ADMIN_URL = "http://localhost:9000" +const DEFAULT_ADMIN_URL = "/" const DEFAULT_STORE_CORS = "http://localhost:8000" const DEFAULT_DATABASE_URL = "postgres://localhost/medusa-starter-default" const DEFAULT_ADMIN_CORS =