This commit is contained in:
Benjamin Toby
2025-04-17 11:42:53 +01:00
parent ba1a4aeeb8
commit ee23d71b66
11 changed files with 74 additions and 23 deletions
+2 -1
View File
@@ -25,8 +25,9 @@ export default async function getSchema({
field,
table,
user_id,
env,
}: GetSchemaAPIParam): Promise<GetSchemaReturn> {
const grabedHostNames = grabHostNames();
const grabedHostNames = grabHostNames({ env });
const { host, port, scheme } = grabedHostNames;
/**
+1
View File
@@ -305,6 +305,7 @@ export interface GetSchemaRequestQuery {
table?: string;
field?: string;
user_id?: string | number;
env?: { [k: string]: string };
}
export interface GetSchemaAPICredentialsParam {
+13 -8
View File
@@ -12,26 +12,31 @@ type GrabHostNamesReturn = {
type Param = {
userId?: string | number;
env?: { [k: string]: string };
};
/**
* # Grab Names For Query
*/
export default function grabHostNames(param?: Param): GrabHostNamesReturn {
const scheme = process.env.DSQL_HTTP_SCHEME;
const localHost = process.env.DSQL_LOCAL_HOST;
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
const remoteHost = process.env.DSQL_API_REMOTE_HOST?.match(/.*\..*/)
? process.env.DSQL_API_REMOTE_HOST
const finalEnv = param?.env
? { ...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 remoteHost = finalEnv["DSQL_API_REMOTE_HOST"]?.match(/.*\..*/)
? finalEnv["DSQL_API_REMOTE_HOST"]
: undefined;
const remoteHostPort = process.env.DSQL_API_REMOTE_HOST_PORT?.match(/./)
? process.env.DSQL_API_REMOTE_HOST_PORT
const remoteHostPort = finalEnv["DSQL_API_REMOTE_HOST_PORT"]?.match(/./)
? finalEnv["DSQL_API_REMOTE_HOST_PORT"]
: undefined;
return {
host: remoteHost || localHost || "datasquirel.com",
port: remoteHostPort || localHostPort || 443,
scheme: scheme?.match(/^http$/i) ? http : https,
user_id: param?.userId || String(process.env.DSQL_API_USER_ID || 0),
user_id: param?.userId || String(finalEnv["DSQL_API_USER_ID"] || 0),
};
}