Browse Source

fix(gui-v2): include host from NC_DB url

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3528/head
Pranav C 2 years ago
parent
commit
9c557c9043
  1. 75
      packages/nocodb/src/lib/utils/NcConfigFactory.ts

75
packages/nocodb/src/lib/utils/NcConfigFactory.ts

@ -59,23 +59,23 @@ const knownQueryParams = [
}, },
{ {
parameter: 'keyFilePath', parameter: 'keyFilePath',
aliases: [] aliases: [],
}, },
{ {
parameter: 'certFilePath', parameter: 'certFilePath',
aliases: [] aliases: [],
}, },
{ {
parameter: 'caFilePath', parameter: 'caFilePath',
aliases: [] aliases: [],
}, },
{ {
parameter: 'ssl', parameter: 'ssl',
aliases: [] aliases: [],
}, },
{ {
parameter: 'options', parameter: 'options',
aliases: ['opt', 'opts'] aliases: ['opt', 'opts'],
}, },
]; ];
@ -195,9 +195,11 @@ export default class NcConfigFactory implements NcConfig {
}, },
} as any; } as any;
} else { } else {
const parsedQuery = {} const parsedQuery = {};
for (const [key, value] of url.searchParams.entries()) { for (const [key, value] of url.searchParams.entries()) {
const fnd = knownQueryParams.find((param) => param.parameter === key || param.aliases.includes(key)) const fnd = knownQueryParams.find(
(param) => param.parameter === key || param.aliases.includes(key)
);
if (fnd) { if (fnd) {
parsedQuery[fnd.parameter] = value; parsedQuery[fnd.parameter] = value;
} else { } else {
@ -209,7 +211,8 @@ export default class NcConfigFactory implements NcConfig {
client: url.protocol.replace(':', ''), client: url.protocol.replace(':', ''),
connection: { connection: {
...defaultConnectionConfig, ...defaultConnectionConfig,
...parsedQuery ...parsedQuery,
host: url.hostname,
}, },
// pool: { // pool: {
// min: 1, // min: 1,
@ -303,9 +306,11 @@ export default class NcConfigFactory implements NcConfig {
: {}), : {}),
}; };
} else { } else {
const parsedQuery = {} const parsedQuery = {};
for (const [key, value] of url.searchParams.entries()) { for (const [key, value] of url.searchParams.entries()) {
const fnd = knownQueryParams.find((param) => param.parameter === key || param.aliases.includes(key)) const fnd = knownQueryParams.find(
(param) => param.parameter === key || param.aliases.includes(key)
);
if (fnd) { if (fnd) {
parsedQuery[fnd.parameter] = value; parsedQuery[fnd.parameter] = value;
} else { } else {
@ -318,7 +323,7 @@ export default class NcConfigFactory implements NcConfig {
connection: { connection: {
...defaultConnectionConfig, ...defaultConnectionConfig,
...parsedQuery, ...parsedQuery,
host: url.hostname host: url.hostname,
}, },
acquireConnectionTimeout: 600000, acquireConnectionTimeout: 600000,
...(url.searchParams.has('search_path') ...(url.searchParams.has('search_path')
@ -637,7 +642,7 @@ export default class NcConfigFactory implements NcConfig {
} }
} }
public static extractXcUrlFromJdbc(url: string, rtConfig: boolean = false) { public static extractXcUrlFromJdbc(url: string, rtConfig = false) {
// drop the jdbc prefix // drop the jdbc prefix
if (url.startsWith('jdbc:')) { if (url.startsWith('jdbc:')) {
url = url.substring(5); url = url.substring(5);
@ -645,9 +650,19 @@ export default class NcConfigFactory implements NcConfig {
const config = parseDbUrl(url); const config = parseDbUrl(url);
const parsedConfig: { driver?: string, host?: string, port?: string, database?: string, user?:string, password?: string, ssl?: string } = {} const parsedConfig: {
driver?: string;
host?: string;
port?: string;
database?: string;
user?: string;
password?: string;
ssl?: string;
} = {};
for (const [key, value] of Object.entries(config)) { for (const [key, value] of Object.entries(config)) {
const fnd = knownQueryParams.find((param) => param.parameter === key || param.aliases.includes(key)) const fnd = knownQueryParams.find(
(param) => param.parameter === key || param.aliases.includes(key)
);
if (fnd) { if (fnd) {
parsedConfig[fnd.parameter] = value; parsedConfig[fnd.parameter] = value;
} else { } else {
@ -655,28 +670,42 @@ export default class NcConfigFactory implements NcConfig {
} }
} }
if (!parsedConfig?.port) parsedConfig.port = defaultClientPortMapping[driverClientMapping[parsedConfig.driver] || parsedConfig.driver]; if (!parsedConfig?.port)
parsedConfig.port =
defaultClientPortMapping[
driverClientMapping[parsedConfig.driver] || parsedConfig.driver
];
if (rtConfig) { if (rtConfig) {
const { driver, ...connectionConfig } = parsedConfig; const { driver, ...connectionConfig } = parsedConfig;
const client = driverClientMapping[driver] || driver; const client = driverClientMapping[driver] || driver;
const avoidSSL = ['localhost', '127.0.0.1', 'host.docker.internal', '172.17. 0.1'] const avoidSSL = [
'localhost',
'127.0.0.1',
'host.docker.internal',
'172.17. 0.1',
];
if (client === 'pg' && !connectionConfig?.ssl && !avoidSSL.includes(connectionConfig.host)) { if (
client === 'pg' &&
!connectionConfig?.ssl &&
!avoidSSL.includes(connectionConfig.host)
) {
connectionConfig.ssl = 'true'; connectionConfig.ssl = 'true';
} }
return { return {
client: client, client: client,
connection: { connection: {
...connectionConfig ...connectionConfig,
} },
} as any; } as any;
} }
const { driver, host, port, database, user, password, ...extra } = parsedConfig; const { driver, host, port, database, user, password, ...extra } =
parsedConfig;
const extraParams = []; const extraParams = [];
@ -684,7 +713,11 @@ export default class NcConfigFactory implements NcConfig {
extraParams.push(`${key}=${value}`); extraParams.push(`${key}=${value}`);
} }
const res = `${driverClientMapping[driver] || driver}://${host}${port ? `:${port}` : ''}?${user ? `u=${user}&` : ''}${password ? `p=${password}&` : ''}${database ? `d=${database}&` : ''}${extraParams.join('&')}`; const res = `${driverClientMapping[driver] || driver}://${host}${
port ? `:${port}` : ''
}?${user ? `u=${user}&` : ''}${password ? `p=${password}&` : ''}${
database ? `d=${database}&` : ''
}${extraParams.join('&')}`;
return res; return res;
} }

Loading…
Cancel
Save