dsql-admin/dsql-app/package-shared/utils/grab-host-names.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-11-26 09:31:39 +00:00
// @ts-check
const https = require("https");
const http = require("http");
/**
* @typedef {object} GrabHostNamesReturn
* @property {string} host
* @property {number | string} port
* @property {typeof http | typeof https} scheme
2024-11-27 11:23:44 +00:00
* @property {string | number} user_id
2024-11-26 09:31:39 +00:00
*/
/**
* # Grab Names For Query
* @returns {GrabHostNamesReturn}
*/
function grabHostNames() {
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
: undefined;
const remoteHostPort = process.env.DSQL_API_REMOTE_HOST_PORT?.match(/./)
? process.env.DSQL_API_REMOTE_HOST_PORT
: undefined;
return {
host: remoteHost || localHost || "datasquirel.com",
port: remoteHostPort || localHostPort || 443,
scheme: scheme?.match(/^http$/i) ? http : https,
2024-11-27 11:23:44 +00:00
user_id: String(process.env.DSQL_API_USER_ID || 0),
2024-11-26 09:31:39 +00:00
};
}
module.exports = grabHostNames;