Skip to content

Commit

Permalink
Adding code changes from pull request: aws-solutions#158
Browse files Browse the repository at this point in the history
  • Loading branch information
Susan123456789 committed Feb 3, 2020
1 parent a7ee268 commit 46643a5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
14 changes: 13 additions & 1 deletion source/image-handler/image-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,23 @@ class ImageRequest {
const request = s3.getObject(imageLocation).promise();
try {
const originalImage = await request;
if (originalImage.ContentType) {
this.ContentType = originalImage.ContentType;
}
if (originalImage.Expires) {
this.Expires = new Date(originalImage.Expires).toUTCString();
}
if (originalImage.LastModified) {
this.LastModified = new Date(originalImage.LastModified).toUTCString();
}
if (originalImage.CacheControl) {
this.CacheControl = originalImage.CacheControl;
}
return Promise.resolve(originalImage.Body);
}
catch(err) {
return Promise.reject({
status: 500,
status: ("NoSuchKey" == err.code) ? 404 : 500,
code: err.code,
message: err.message
})
Expand Down
10 changes: 7 additions & 3 deletions source/image-handler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ exports.handler = async (event) => {
const request = await imageRequest.setup(event);
console.log(request);
const processedRequest = await imageHandler.process(request);
const headers = getResponseHeaders();
headers["Content-Type"] = request.ContentType;
headers["Expires"] = request.Expires;
headers["Last-Modified"] = request.LastModified;
headers["Cache-Control"] = request.CacheControl;
const response = {
"statusCode": 200,
"headers" : getResponseHeaders(),
"headers" : headers,
"body": processedRequest,
"isBase64Encoded": true
}
Expand All @@ -51,8 +56,7 @@ const getResponseHeaders = (isErr) => {
const headers = {
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
"Access-Control-Allow-Credentials": true,
"Content-Type": "image"
"Access-Control-Allow-Credentials": true
}
if (corsEnabled) {
headers["Access-Control-Allow-Origin"] = process.env.CORS_ORIGIN;
Expand Down
8 changes: 4 additions & 4 deletions source/image-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"private": true,
"dependencies": {
"mocha": "^6.1.4",
"sharp": "^0.23.3",
"sinon": "^7.3.2",
"nyc": "^14.0.0"
"nyc": "^14.0.0",
"sharp": "^0.23.4",
"sinon": "^7.3.2"
},
"devDependencies": {
"aws-sdk": "^2.437.0",
Expand All @@ -23,7 +23,7 @@
"build:init": "rm -rf package-lock.json && rm -rf dist && rm -rf node_modules",
"build:zip": "zip -rq image-handler.zip . -x template.yml",
"build:dist": "mkdir dist && mv image-handler.zip dist/",
"build": "npm run build:init && npm install --production && npm run build:zip && npm run build:dist"
"build": "npm run build:init && npm install --arch=x64 --platform=linux --production && npm run build:zip && npm run build:dist"
},
"license": "Apache-2.0"
}

0 comments on commit 46643a5

Please sign in to comment.