Add: Optional DB SSH
This commit is contained in:
parent
56c1c4ac76
commit
4d53448465
@ -2,9 +2,13 @@ import { env } from '$lib/env';
|
|||||||
import postgres from 'postgres';
|
import postgres from 'postgres';
|
||||||
import ssh2 from 'ssh2';
|
import ssh2 from 'ssh2';
|
||||||
|
|
||||||
// @ts-ignore
|
/**
|
||||||
export const sql = postgres(
|
* @returns {postgres.Options<{}>}
|
||||||
{
|
*/
|
||||||
|
function getPostreConfig() {
|
||||||
|
if (env.SSH_ENABLE == 'true') {
|
||||||
|
// with ssh
|
||||||
|
return {
|
||||||
host: env.PG_HOST,
|
host: env.PG_HOST,
|
||||||
port: parseInt(env.PG_PORT),
|
port: parseInt(env.PG_PORT),
|
||||||
database: env.PG_DATABASE,
|
database: env.PG_DATABASE,
|
||||||
@ -28,4 +32,20 @@ export const sql = postgres(
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// no ssh
|
||||||
|
return {
|
||||||
|
host: env.PG_HOST,
|
||||||
|
port: parseInt(env.PG_PORT),
|
||||||
|
database: env.PG_DATABASE,
|
||||||
|
username: env.PG_USERNAME,
|
||||||
|
password: env.PG_PASSWORD,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const sql = postgres(
|
||||||
|
getPostreConfig()
|
||||||
);
|
);
|
||||||
|
|||||||
@ -5,6 +5,7 @@ export type Env = {
|
|||||||
PG_PORT: string,
|
PG_PORT: string,
|
||||||
PG_DATABASE: string,
|
PG_DATABASE: string,
|
||||||
|
|
||||||
|
SSH_ENABLE: string,
|
||||||
SSH_HOST: string,
|
SSH_HOST: string,
|
||||||
SSH_PORT: string,
|
SSH_PORT: string,
|
||||||
SSH_USERNAME: string,
|
SSH_USERNAME: string,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user