Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling ALB Support #201

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions source/image-handler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,30 @@ exports.handler = async (event) => {
console.log(event);
const imageRequest = new ImageRequest();
const imageHandler = new ImageHandler();
const isALB = event.requestContext && event.requestContext.hasOwnProperty("elb");
try {
const request = await imageRequest.setup(event);
console.log(request);
const processedRequest = await imageHandler.process(request);

const headers = getResponseHeaders();
const headers = getResponseHeaders(false, isALB);
headers["Content-Type"] = request.ContentType;
headers["Expires"] = request.Expires;
headers["Last-Modified"] = request.LastModified;
headers["Cache-Control"] = request.CacheControl;

return {
"statusCode": 200,
"headers" : headers,
"isBase64Encoded": true,
"headers": headers,
"body": processedRequest,
"isBase64Encoded": true
};
}
} catch (err) {
console.log(err);

return {
"statusCode": err.status,
"headers" : getResponseHeaders(true),
"isBase64Encoded": false,
"headers": getResponseHeaders(true, isALB),
"body": JSON.stringify(err),
"isBase64Encoded": false
};
}
}
Expand All @@ -52,12 +51,14 @@ exports.handler = async (event) => {
* or error condition.
* @param {boolean} isErr - has an error been thrown?
*/
const getResponseHeaders = (isErr) => {
const getResponseHeaders = (isErr = false, isALB = false) => {
const corsEnabled = (process.env.CORS_ENABLED === "Yes");
const headers = {
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
"Access-Control-Allow-Credentials": true
}
if (!isALB) {
headers["Access-Control-Allow-Credentials"] = true;
}
if (corsEnabled) {
headers["Access-Control-Allow-Origin"] = process.env.CORS_ORIGIN;
Expand Down