Skip to content

Commit c721e3b

Browse files
authored
Merge pull request #20 from wesreid/feature/add-proxy-handling
always return cors headers
2 parents ec1b9dc + d581b1f commit c721e3b

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/lib/lambda-route-proxy-entry-handler.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ export const lambdaRouteProxyEntryHandler =
193193
...retVal,
194194
isBase64Encoded: false,
195195
headers: {
196+
"Access-Control-Allow-Origin": "*",
197+
"Access-Control-Allow-Methods":
198+
"GET, POST, PUT, DELETE, PATCH, OPTIONS",
199+
"Access-Control-Allow-Headers":
200+
"Content-Type, Authorization, X-Amz-Date, X-Api-Key, X-Amz-Security-Token",
201+
"Access-Control-Allow-Credentials": "true",
196202
"Content-Type": "application/json",
197203
...(retVal.headers ?? {}),
198204
},
@@ -201,13 +207,13 @@ export const lambdaRouteProxyEntryHandler =
201207
? JSON.stringify(retVal.body)
202208
: retVal.body,
203209
};
204-
} else {
205-
retVal = {
206-
statusCode: 200,
207-
body: JSON.stringify(retVal),
208-
"Content-Type": "application/json",
209-
};
210210
}
211+
} else {
212+
retVal = {
213+
statusCode: 200,
214+
body: JSON.stringify(retVal),
215+
"Content-Type": "application/json",
216+
};
211217
}
212218
} catch (error: any) {
213219
console.error(JSON.stringify({ error, stack: error.stack }));
@@ -218,7 +224,8 @@ export const lambdaRouteProxyEntryHandler =
218224
let statusCode = 500;
219225

220226
if (isProxied) {
221-
const isOptions = (event.requestContext as any).httpMethod === "OPTIONS";
227+
const isOptions =
228+
(event.requestContext as any).httpMethod === "OPTIONS";
222229
if (isOptions) {
223230
statusCode = 200;
224231
} else {

0 commit comments

Comments
 (0)