diff --git a/packages/core/utils/src/modules-sdk/__tests__/load-database-config.spec.ts b/packages/core/utils/src/modules-sdk/__tests__/load-database-config.spec.ts index ae59dff6dc..3768f4be0f 100644 --- a/packages/core/utils/src/modules-sdk/__tests__/load-database-config.spec.ts +++ b/packages/core/utils/src/modules-sdk/__tests__/load-database-config.spec.ts @@ -111,6 +111,28 @@ describe("loadDatabaseConfig", function () { }) }) + it("should return the local configuration using the options", function () { + process.env.POSTGRES_URL = "postgres://localhost:5432/medusa" + const options = { + database: { + clientUrl: "postgres://127.0.0.1:5432/medusa-test", + }, + } + + let config = loadDatabaseConfig("product", options) + + expect(config).toEqual({ + clientUrl: options.database.clientUrl, + driverOptions: { + connection: { + ssl: false, + }, + }, + debug: false, + schema: "", + }) + }) + it("should return the remote configuration using the options", function () { process.env.POSTGRES_URL = "postgres://localhost:5432/medusa" const options = { @@ -135,6 +157,52 @@ describe("loadDatabaseConfig", function () { }) }) + it("should return the local configuration using the client url ssl_mode=disable", function () { + process.env.POSTGRES_URL = "postgres://localhost:5432/medusa" + const options = { + database: { + clientUrl: + "postgres://https://test.com:5432/medusa-test?ssl_mode=disable", + }, + } + + let config = loadDatabaseConfig("product", options) + + expect(config).toEqual({ + clientUrl: options.database.clientUrl, + driverOptions: { + connection: { + ssl: false, + }, + }, + debug: false, + schema: "", + }) + }) + + it("should return the remote configuration using the client url ssl_mode=false", function () { + process.env.POSTGRES_URL = "postgres://localhost:5432/medusa" + const options = { + database: { + clientUrl: + "postgres://https://test.com:5432/medusa-test?ssl_mode=disable", + }, + } + + let config = loadDatabaseConfig("product", options) + + expect(config).toEqual({ + clientUrl: options.database.clientUrl, + driverOptions: { + connection: { + ssl: false, + }, + }, + debug: false, + schema: "", + }) + }) + it("should throw if no clientUrl is provided", function () { let error try { diff --git a/packages/core/utils/src/modules-sdk/load-module-database-config.ts b/packages/core/utils/src/modules-sdk/load-module-database-config.ts index b92defb173..6f1af15c01 100644 --- a/packages/core/utils/src/modules-sdk/load-module-database-config.ts +++ b/packages/core/utils/src/modules-sdk/load-module-database-config.ts @@ -31,7 +31,9 @@ function getDefaultDriverOptions(clientUrl: string) { } if (clientUrl) { - return clientUrl.match(/localhost/i) ? localOptions : remoteOptions + return clientUrl.match(/localhost|127\.0\.0\.1|ssl_mode=(disable|false)/i) + ? localOptions + : remoteOptions } return process.env.NODE_ENV?.match(/prod/i)