Updates
This commit is contained in:
@@ -2,12 +2,14 @@
|
||||
|
||||
import https from "https";
|
||||
import http from "http";
|
||||
import { APIConnectionOptions } from "../types";
|
||||
|
||||
type GrabHostNamesReturn = {
|
||||
export type GrabHostNamesReturn = {
|
||||
host: string;
|
||||
port: number | string;
|
||||
scheme: typeof http | typeof https;
|
||||
user_id: string | number;
|
||||
apiKey?: string;
|
||||
};
|
||||
|
||||
type Param = {
|
||||
@@ -16,6 +18,7 @@ type Param = {
|
||||
remoteHost?: string;
|
||||
remoteHostPort?: string;
|
||||
useDefault?: boolean;
|
||||
apiConnectionConfig?: APIConnectionOptions;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -26,17 +29,26 @@ export default function grabHostNames(param?: Param): GrabHostNamesReturn {
|
||||
? { ...process.env, ...param.env }
|
||||
: process.env;
|
||||
|
||||
const scheme = finalEnv["DSQL_HTTP_SCHEME"];
|
||||
const localHost = finalEnv["DSQL_LOCAL_HOST"];
|
||||
const localHostPort = finalEnv["DSQL_LOCAL_HOST_PORT"];
|
||||
const scheme =
|
||||
param?.apiConnectionConfig?.scheme || finalEnv["DSQL_HTTP_SCHEME"];
|
||||
const localHost = param?.apiConnectionConfig?.isLocalhost
|
||||
? "localhost"
|
||||
: finalEnv["DSQL_LOCAL_HOST"];
|
||||
const localHostPort =
|
||||
param?.apiConnectionConfig?.localhostPort ||
|
||||
finalEnv["DSQL_LOCAL_HOST_PORT"];
|
||||
|
||||
const remoteHost = param?.useDefault
|
||||
? undefined
|
||||
: param?.apiConnectionConfig?.remoteHost
|
||||
? param?.apiConnectionConfig?.remoteHost
|
||||
: finalEnv["DSQL_API_REMOTE_HOST"]?.match(/.*\..*/)
|
||||
? finalEnv["DSQL_API_REMOTE_HOST"]
|
||||
: undefined;
|
||||
const remoteHostPort = param?.useDefault
|
||||
? undefined
|
||||
: param?.apiConnectionConfig?.remoteHostPort
|
||||
? param?.apiConnectionConfig?.remoteHostPort
|
||||
: finalEnv["DSQL_API_REMOTE_HOST_PORT"]?.match(/./)
|
||||
? finalEnv["DSQL_API_REMOTE_HOST_PORT"]
|
||||
: undefined;
|
||||
@@ -46,5 +58,10 @@ export default function grabHostNames(param?: Param): GrabHostNamesReturn {
|
||||
port: remoteHostPort || localHostPort || 443,
|
||||
scheme: scheme?.match(/^http$/i) ? http : https,
|
||||
user_id: param?.userId || String(finalEnv["DSQL_API_USER_ID"] || 0),
|
||||
apiKey:
|
||||
param?.apiConnectionConfig?.apiKey ||
|
||||
process.env.DSQL_FULL_ACCESS_API_KEY ||
|
||||
process.env.DSQL_API_KEY ||
|
||||
process.env.DSQL_READ_ONLY_API_KEY,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user