diff --git a/cors-proxy/index.mjs b/cors-proxy/index.mjs index 0a7cf758..abc787af 100644 --- a/cors-proxy/index.mjs +++ b/cors-proxy/index.mjs @@ -3,9 +3,11 @@ import process from 'node:process'; export const handler = async (event) => { const targetUrl = process.env.PROXY_TARGET_URL; + const body = event?.isBase64Encoded ? atob(event.body) : event.body; + const response = await fetch(targetUrl, { method: 'POST', - body: event.body, + body, headers: { 'Content-type': 'application/x-www-form-urlencoded', }, @@ -29,6 +31,7 @@ export const handler = async (event) => { statusCode: response.status, message: response.message, headers: response.headers, + targetUrl, }); return { diff --git a/cors-proxy/server.mjs b/cors-proxy/server.mjs index 63250a5b..6b82c4ce 100644 --- a/cors-proxy/server.mjs +++ b/cors-proxy/server.mjs @@ -2,6 +2,7 @@ import http from 'http'; import { handler } from './index.mjs'; import url from 'url'; import process from 'node:process'; +import { Buffer } from 'node:buffer'; const allowedOrigin = process.env.PROXY_ALLOWED_ORIGIN || '*'; @@ -43,7 +44,8 @@ const server = http.createServer(async (req, res) => { const lambdaEvent = { httpMethod: req.method, queryStringParameters: parsedUrl.query, - body: body, + body: Buffer.from(body).toString('base64'), + isBase64Encoded: true, }; // Call the handler (same code used in AWS Lambda)