-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1014 from jboolean/edge-redirect
Add edge redirection for missing resolutions to full res
- Loading branch information
Showing
6 changed files
with
11,085 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# package directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Serverless directories | ||
.serverless | ||
.build | ||
|
||
secrets.*.yml | ||
tsoa-build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { CloudFrontResponseHandler } from "aws-lambda"; | ||
|
||
export const handler: CloudFrontResponseHandler = async (event) => { | ||
// Extract the request and response from the event object | ||
const request = event.Records[0].cf.request; | ||
const response = event.Records[0].cf.response; | ||
|
||
// Get the requested URI | ||
const requestedUri = request.uri; | ||
|
||
if (response.status === "404") { | ||
const match = requestedUri.match(/^\/(\d+)\-(\w+)\/(.*)$/); | ||
|
||
// If they requested a specific width that does not exist, redirect to full width | ||
if (match) { | ||
const [, _width, format, rootKey] = match; | ||
return { | ||
status: "302", | ||
statusDescription: "Found", | ||
headers: { | ||
...response.headers, | ||
location: [ | ||
{ | ||
key: "Location", | ||
value: `/${format}/${rootKey}`, | ||
}, | ||
], | ||
}, | ||
}; | ||
} | ||
} | ||
|
||
// Return the original response if no redirect is needed | ||
return response; | ||
}; |
Oops, something went wrong.