This commit is contained in:
Benjamin Toby
2023-09-21 17:51:08 +01:00
parent 44b013147e
commit 069db84289
17 changed files with 414 additions and 91 deletions
@@ -4,6 +4,7 @@
* Imports
*/
const https = require("https");
const http = require("http");
const path = require("path");
const fs = require("fs");
@@ -38,6 +39,10 @@ async function updateApiSchemaFromLocalDb() {
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;
/**
* Make https request
*
@@ -63,7 +68,9 @@ async function updateApiSchemaFromLocalDb() {
const reqPayload = reqPayloadString;
const httpsRequest = https.request(
const httpsRequest = (
scheme?.match(/^http$/i) ? http : https
).request(
{
method: "POST",
headers: {
@@ -71,8 +78,8 @@ async function updateApiSchemaFromLocalDb() {
"Content-Length": Buffer.from(reqPayload).length,
Authorization: key,
},
port: 443,
hostname: "datasquirel.com",
port: localHostPort || 443,
hostname: localHost || "datasquirel.com",
path: `/api/query/update-schema-from-single-database`,
},
+14 -3
View File
@@ -48,12 +48,22 @@ const encryptionSalt = process.env.DSQL_ENCRYPTION_SALT || "";
*
* @returns { Promise<FunctionReturn> }
*/
async function localGoogleAuth({ dbSchema, token, clientId, response, additionalFields }) {
async function localGoogleAuth({
dbSchema,
token,
clientId,
response,
additionalFields,
}) {
/**
* Send Response
*
* @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;
try {
/**
* Grab User data
@@ -63,7 +73,7 @@ async function localGoogleAuth({ dbSchema, token, clientId, response, additional
*/
const payloadResponse = await httpsRequest({
method: "POST",
hostname: "datasquirel.com",
hostname: localHost || "datasquirel.com",
path: "/user/grab-google-user-from-token",
body: {
token: token,
@@ -114,7 +124,8 @@ async function localGoogleAuth({ dbSchema, token, clientId, response, additional
};
}
const { given_name, family_name, email, sub, picture, email_verified } = payload;
const { given_name, family_name, email, sub, picture, email_verified } =
payload;
const payloadObject = {
email: email || "",
+11 -4
View File
@@ -3,6 +3,7 @@
* ==============================================================================
*/
const https = require("https");
const http = require("http");
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
@@ -27,14 +28,18 @@ const https = require("https");
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;
////////////////////////////////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
let requestOptions = {
method: method,
hostname: hostname,
port: 443,
hostname: localHost || hostname,
port: localHostPort || 443,
headers: {},
};
@@ -44,7 +49,9 @@ function httpsRequest({ url, method, hostname, path, href, headers, body }) {
if (headers) requestOptions.headers = headers;
if (body) {
requestOptions.headers["Content-Type"] = "application/json";
requestOptions.headers["Content-Length"] = Buffer.from(reqPayloadString || "").length;
requestOptions.headers["Content-Length"] = Buffer.from(
reqPayloadString || ""
).length;
}
////////////////////////////////////////////////
@@ -52,7 +59,7 @@ function httpsRequest({ url, method, hostname, path, href, headers, body }) {
////////////////////////////////////////////////
return new Promise((res, rej) => {
const httpsRequest = https.request(
const httpsRequest = (scheme?.match(/^http$/i) ? http : https).request(
/* ====== Request Options object ====== */
// @ts-ignore
url ? url : requestOptions,