aws-lambda#CloudFrontRequestHandler TypeScript Examples
The following examples show how to use
aws-lambda#CloudFrontRequestHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: origin-request.ts From roamjs-com with MIT License | 6 votes |
handler: CloudFrontRequestHandler = (event, _, callback) => {
const request = event.Records[0].cf.request;
const olduri = request.uri;
if (movedUris.includes(olduri)) {
request.uri = olduri.replace(/\.js$/, "/main.js");
console.log("Mapped", olduri, "to", request.uri);
} else if (olduri.endsWith("/") && olduri.length > 1) {
request.uri = olduri.replace(/\/$/, "");
console.log("Mapped", olduri, "to", request.uri);
}
return callback(null, request);
}
Example #2
Source File: viewer-request.ts From roamjs-com with MIT License | 6 votes |
handler: CloudFrontRequestHandler = (event, _, callback) => {
const request = event.Records[0].cf.request;
const olduri = request.uri;
const redirect = (newUri: string) => {
const response = {
status: "301",
statusDescription: "Moved Permanently",
headers: {
location: [
{
key: "Location",
value: `https://roamjs.com${newUri}`,
},
],
},
};
return callback(null, response);
}
if (/^\/docs(\/extensions)?/.test(olduri)) {
const newUri = olduri.replace(/^\/docs(\/extensions)?/, "/extensions");
return redirect(newUri);
} else if (/^\/services\/social(\/)?/.test(olduri)) {
const newUri = '/extensions/twitter';
return redirect(newUri);
} else if (/^\/services(.*)$/.test(olduri)) {
const newUri = olduri.replace(/^\/services(.*)$/, "/extensions$1");
return redirect(newUri);
}
return callback(null, request);
}