chore(): remove ssl_mode from url and also use sslmode (#13568)

* chore(): remove ssl_mode from url and also use sslmode

* improve regexp

* chore(): remove ssl_mode from url and also use sslmode

* chore(): remove ssl_mode from url and also use sslmode

* Update SSL mode configuration in changeset

Removed 'ssl_mode' from URL and replaced it with 'sslmode'.
This commit is contained in:
Adrien de Peretti
2025-09-22 12:11:43 +02:00
committed by GitHub
parent 730d73306d
commit 92d30b28f4
4 changed files with 60 additions and 5 deletions

View File

@@ -0,0 +1,6 @@
---
"@medusajs/framework": patch
"@medusajs/utils": patch
---
chore(): remove ssl_mode from url and also use sslmode

View File

@@ -38,8 +38,18 @@ export async function pgConnectionLoader(): Promise<
delete driverOptions.pool delete driverOptions.pool
const clientUrl = connectionString?.replace(
/(\?|&)ssl_mode=[^&]*(&|$)/gi,
(match, prefix, suffix) => {
if (prefix === "?" && suffix === "&") return "?"
if (prefix === "?" && suffix === "") return ""
if (prefix === "&") return suffix
return ""
}
)
const pgConnection = ModulesSdkUtils.createPgConnection({ const pgConnection = ModulesSdkUtils.createPgConnection({
clientUrl: connectionString, clientUrl,
schema, schema,
driverOptions, driverOptions,
pool: { pool: {

View File

@@ -169,7 +169,30 @@ describe("loadDatabaseConfig", function () {
let config = loadDatabaseConfig("product", options) let config = loadDatabaseConfig("product", options)
expect(config).toEqual({ expect(config).toEqual({
clientUrl: options.database.clientUrl, clientUrl: "postgres://https://test.com:5432/medusa-test",
driverOptions: {
connection: {
ssl: false,
},
},
debug: false,
schema: "",
})
})
it("should return the local configuration using the client url sslmode=disable", function () {
process.env.DATABASE_URL = "postgres://localhost:5432/medusa"
const options = {
database: {
clientUrl:
"postgres://https://test.com:5432/medusa-test?sslmode=disable",
},
}
let config = loadDatabaseConfig("product", options)
expect(config).toEqual({
clientUrl: "postgres://https://test.com:5432/medusa-test?sslmode=disable",
driverOptions: { driverOptions: {
connection: { connection: {
ssl: false, ssl: false,
@@ -185,14 +208,14 @@ describe("loadDatabaseConfig", function () {
const options = { const options = {
database: { database: {
clientUrl: clientUrl:
"postgres://https://test.com:5432/medusa-test?ssl_mode=disable", "postgres://https://test.com:5432/medusa-test?ssl_mode=false",
}, },
} }
let config = loadDatabaseConfig("product", options) let config = loadDatabaseConfig("product", options)
expect(config).toEqual({ expect(config).toEqual({
clientUrl: options.database.clientUrl, clientUrl: "postgres://https://test.com:5432/medusa-test",
driverOptions: { driverOptions: {
connection: { connection: {
ssl: false, ssl: false,

View File

@@ -31,7 +31,9 @@ function getDefaultDriverOptions(clientUrl: string) {
} }
if (clientUrl) { if (clientUrl) {
return clientUrl.match(/localhost|127\.0\.0\.1|ssl_mode=(disable|false)/i) return clientUrl.match(
/localhost|127\.0\.0\.1|ssl_mode=(disable|false)|sslmode=(disable)/i
)
? localOptions ? localOptions
: remoteOptions : remoteOptions
} }
@@ -105,5 +107,19 @@ export function loadDatabaseConfig(
) )
} }
/**
* Remove the ssl_mode parameter since it is not supported by
* the database
* driver but rather an internal parameter used by us.
*/
database.clientUrl = database.clientUrl?.replace(
/(\?|&)ssl_mode=[^&]*(&|$)/gi,
(match, prefix, suffix) => {
if (prefix === "?" && suffix === "&") return "?"
if (prefix === "?" && suffix === "") return ""
if (prefix === "&") return suffix
return ""
}
)
return database return database
} }