Skip to content

Commit

Permalink
Match the AWS data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
wilwade committed Sep 16, 2024
1 parent 71cb16f commit 97df9ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion cors-proxy/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand All @@ -29,6 +31,7 @@ export const handler = async (event) => {
statusCode: response.status,
message: response.message,
headers: response.headers,
targetUrl,
});

return {
Expand Down
4 changes: 3 additions & 1 deletion cors-proxy/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '*';

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 97df9ca

Please sign in to comment.