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:
committed by
GitHub
parent
730d73306d
commit
92d30b28f4
@@ -169,7 +169,30 @@ describe("loadDatabaseConfig", function () {
|
||||
let config = loadDatabaseConfig("product", options)
|
||||
|
||||
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: {
|
||||
connection: {
|
||||
ssl: false,
|
||||
@@ -185,14 +208,14 @@ describe("loadDatabaseConfig", function () {
|
||||
const options = {
|
||||
database: {
|
||||
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)
|
||||
|
||||
expect(config).toEqual({
|
||||
clientUrl: options.database.clientUrl,
|
||||
clientUrl: "postgres://https://test.com:5432/medusa-test",
|
||||
driverOptions: {
|
||||
connection: {
|
||||
ssl: false,
|
||||
|
||||
@@ -31,7 +31,9 @@ function getDefaultDriverOptions(clientUrl: string) {
|
||||
}
|
||||
|
||||
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
|
||||
: 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user