Major Bugfix and Refactoring
This commit is contained in:
@@ -7,6 +7,7 @@ const https = require("https");
|
||||
const http = require("http");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const grabHostNames = require("../../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@@ -38,10 +39,7 @@ async function updateApiSchemaFromLocalDb() {
|
||||
const key = process.env.DSQL_KEY || "";
|
||||
|
||||
const dbSchema = JSON.parse(fs.readFileSync(dbSchemaPath, "utf8"));
|
||||
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
/**
|
||||
* Make https request
|
||||
@@ -68,9 +66,7 @@ async function updateApiSchemaFromLocalDb() {
|
||||
|
||||
const reqPayload = reqPayloadString;
|
||||
|
||||
const httpsRequest = (
|
||||
scheme?.match(/^http$/i) ? http : https
|
||||
).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -78,8 +74,8 @@ async function updateApiSchemaFromLocalDb() {
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: localHostPort || 443,
|
||||
hostname: localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/query/update-schema-from-single-database`,
|
||||
},
|
||||
|
||||
|
||||
@@ -6,13 +6,9 @@
|
||||
* ==============================================================================
|
||||
*/
|
||||
const http = require("http");
|
||||
const https = require("https");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const encrypt = require("../../../functions/encrypt");
|
||||
const decrypt = require("../../../functions/decrypt");
|
||||
const handleSocialDb = require("./utils/handleSocialDb");
|
||||
const httpsRequest = require("./utils/httpsRequest");
|
||||
const grabHostNames = require("../../../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@@ -60,9 +56,7 @@ async function localGoogleAuth({
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
try {
|
||||
/**
|
||||
@@ -73,7 +67,7 @@ async function localGoogleAuth({
|
||||
*/
|
||||
const payloadResponse = await httpsRequest({
|
||||
method: "POST",
|
||||
hostname: localHost || "datasquirel.com",
|
||||
hostname: host,
|
||||
path: "/user/grab-google-user-from-token",
|
||||
body: {
|
||||
token: token,
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
const https = require("https");
|
||||
const http = require("http");
|
||||
const grabHostNames = require("../../../../package-shared/utils/grab-host-names");
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -28,18 +29,17 @@ const http = require("http");
|
||||
function httpsRequest({ url, method, hostname, path, href, headers, body }) {
|
||||
const reqPayloadString = body ? JSON.stringify(body) : null;
|
||||
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
|
||||
/** @type {any} */
|
||||
let requestOptions = {
|
||||
method: method,
|
||||
hostname: localHost || hostname,
|
||||
port: localHostPort || 443,
|
||||
hostname: host,
|
||||
port,
|
||||
headers: {},
|
||||
};
|
||||
|
||||
@@ -59,7 +59,7 @@ function httpsRequest({ url, method, hostname, path, href, headers, body }) {
|
||||
////////////////////////////////////////////////
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
const httpsRequest = (scheme?.match(/^http$/i) ? http : https).request(
|
||||
const httpsRequest = scheme.request(
|
||||
/* ====== Request Options object ====== */
|
||||
// @ts-ignore
|
||||
url ? url : requestOptions,
|
||||
|
||||
Reference in New Issue
Block a user