Skip to content

Commit

Permalink
use a custom https agent for self-signed bypass
Browse files Browse the repository at this point in the history
  • Loading branch information
benphelps committed Aug 24, 2022
1 parent 5c3d6f9 commit ccc3726
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions src/pages/api/proxy.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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,
Expand Down

0 comments on commit ccc3726

Please sign in to comment.