Skip to content

Commit 97df9ca

Browse files
committed
Match the AWS data structure
1 parent 71cb16f commit 97df9ca

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

cors-proxy/index.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import process from 'node:process';
33
export const handler = async (event) => {
44
const targetUrl = process.env.PROXY_TARGET_URL;
55

6+
const body = event?.isBase64Encoded ? atob(event.body) : event.body;
7+
68
const response = await fetch(targetUrl, {
79
method: 'POST',
8-
body: event.body,
10+
body,
911
headers: {
1012
'Content-type': 'application/x-www-form-urlencoded',
1113
},
@@ -29,6 +31,7 @@ export const handler = async (event) => {
2931
statusCode: response.status,
3032
message: response.message,
3133
headers: response.headers,
34+
targetUrl,
3235
});
3336

3437
return {

cors-proxy/server.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import http from 'http';
22
import { handler } from './index.mjs';
33
import url from 'url';
44
import process from 'node:process';
5+
import { Buffer } from 'node:buffer';
56

67
const allowedOrigin = process.env.PROXY_ALLOWED_ORIGIN || '*';
78

@@ -43,7 +44,8 @@ const server = http.createServer(async (req, res) => {
4344
const lambdaEvent = {
4445
httpMethod: req.method,
4546
queryStringParameters: parsedUrl.query,
46-
body: body,
47+
body: Buffer.from(body).toString('base64'),
48+
isBase64Encoded: true,
4749
};
4850

4951
// Call the handler (same code used in AWS Lambda)

0 commit comments

Comments
 (0)