From 2a3620c00c94e969e1913f8165b9851ce1287e10 Mon Sep 17 00:00:00 2001 From: Marco Ceccon Date: Sat, 26 Oct 2024 12:13:48 +0200 Subject: [PATCH] Added proxy for authentication --- cron/requests.js | 11 ++++++++++- pages/api/vonage/send.js | 12 +++++++++++- pages/api/vonage/verify.js | 12 +++++++++++- utils/requests.js | 11 ++++++++++- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/cron/requests.js b/cron/requests.js index 875a5ad..7e76756 100644 --- a/cron/requests.js +++ b/cron/requests.js @@ -68,7 +68,16 @@ const requestAuthenticated = async (endpoint, data, idx = 0) => { "bereal-signature": SIGNATURE, "bereal-device-id": "937v3jb942b0h6u9", "bereal-timezone": "Europe/Paris", - } + }, + "proxy": process.env.USE_PROXY ? { + "protocol": "http", + "host": process.env.PROXY_HOST, + "port": process.env.PROXY_PORT, + "auth": { + "username": process.env.PROXY_USER, + "password": process.env.PROXY_PASS + } + } : null } ); diff --git a/pages/api/vonage/send.js b/pages/api/vonage/send.js index bcb581d..1ce5392 100644 --- a/pages/api/vonage/send.js +++ b/pages/api/vonage/send.js @@ -37,7 +37,16 @@ export default async function handler(req, res) { "bereal-signature": (await fetchSignature()), "bereal-device-id": "937v3jb942b0h6u9", "bereal-timezone": "Europe/Paris", - } + }, + "proxy": process.env.USE_PROXY ? { + "protocol": "http", + "host": process.env.PROXY_HOST, + "port": process.env.PROXY_PORT, + "auth": { + "username": process.env.PROXY_USER, + "password": process.env.PROXY_PASS + } + } : null } ); @@ -48,6 +57,7 @@ export default async function handler(req, res) { }); return; } catch (error) { + console.log(error); return res.status(500).json({ error: "Internal server error", success: false }); } }; \ No newline at end of file diff --git a/pages/api/vonage/verify.js b/pages/api/vonage/verify.js index ac4b451..f78203e 100644 --- a/pages/api/vonage/verify.js +++ b/pages/api/vonage/verify.js @@ -31,7 +31,16 @@ export default async function handler(req, res) { "bereal-signature": (await fetchSignature()), "bereal-device-id": "937v3jb942b0h6u9", "bereal-timezone": "Europe/Paris", - } + }, + "proxy": process.env.USE_PROXY ? { + "protocol": "http", + "host": process.env.PROXY_HOST, + "port": process.env.PROXY_PORT, + "auth": { + "username": process.env.PROXY_USER, + "password": process.env.PROXY_PASS + } + } : null } ); @@ -61,6 +70,7 @@ export default async function handler(req, res) { success: true, }); } catch (e) { + console.log(e) const errorCodes = { "INVALID_CODE": "The code is incorrect.", "SESSION_EXPIRED": "The SMS code has expired. Please re-send the verification code to try again.", diff --git a/utils/requests.js b/utils/requests.js index 40e4f3b..61e1270 100644 --- a/utils/requests.js +++ b/utils/requests.js @@ -79,7 +79,16 @@ const requestAuthenticated = async (endpoint, request, response, method = "get", "bereal-signature": SIGNATURE, "bereal-device-id": "937v3jb942b0h6u9", "bereal-timezone": "Europe/Paris", - } + }, + "proxy": process.env.USE_PROXY ? { + "protocol": "http", + "host": process.env.PROXY_HOST, + "port": process.env.PROXY_PORT, + "auth": { + "username": process.env.PROXY_USER, + "password": process.env.PROXY_PASS + } + } : null } );