From ccc37260a07f9093e7ffecd51a824140bf43ae53 Mon Sep 17 00:00:00 2001 From: Ben Phelps Date: Thu, 25 Aug 2022 01:33:39 +0300 Subject: [PATCH] use a custom https agent for self-signed bypass --- Dockerfile | 3 --- src/pages/api/proxy.js | 13 ++++++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 926106500..ef9c98174 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,9 +26,6 @@ COPY --from=builder /app/package.json ./package.json COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static -# Since we run in a local environment, we need to accept self signed certificates -ENV NODE_TLS_REJECT_UNAUTHORIZED 0 - USER nextjs EXPOSE 3000 ENV PORT 3000 diff --git a/src/pages/api/proxy.js b/src/pages/api/proxy.js index 26495a4ed..1c24757cc 100644 --- a/src/pages/api/proxy.js +++ b/src/pages/api/proxy.js @@ -1,6 +1,4 @@ -function pick(object, keys) { - return; -} +import https from "https"; export default async function handler(req, res) { const headers = ["X-API-Key", "Content-Type", "Authorization"].reduce((obj, key) => { @@ -11,9 +9,14 @@ export default async function handler(req, res) { }, {}); try { + // this agent allows us to bypass the certificate check + // which is required for most self-signed certificates + const httpsAgent = new https.Agent({ + rejectUnauthorized: false, + }); + const result = await fetch(req.query.url, { - strictSSL: false, - rejectUnhauthorized: false, + agent: httpsAgent, method: req.method, headers: headers, body: req.method == "GET" || req.method == "HEAD" ? null : req.body,