This file contains hidden or 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
const path = require('path'); | |
exports.handler = (event, context, callback) => { | |
const { request } = event.Records[0].cf; | |
console.log('Request URI: ', request.uri); | |
const parsedPath = path.parse(request.uri); | |
let newUri; |
This file contains hidden or 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
const path = require('path'); | |
exports.handler = (event, context, callback) => { | |
const { request, config } = event.Records[0].cf; | |
let originalUri = request.uri; | |
const parsedPath = path.parse(originalUri); | |
if (parsedPath.ext === '') { | |
// Every request that does not have an extension should be a route in our |
This file contains hidden or 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
const path = require('path'); | |
const https = require('https'); | |
const zlib = require('zlib'); | |
const downloadContent = (url, callback) => { | |
https.get(url, (res) => { | |
let response; | |
let body = ''; | |
if (res.headers['content-encoding'] === 'gzip') { |
This file contains hidden or 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
exports.handler = (event, context, callback) => { | |
const { request, config } = event.Records[0].cf; | |
let originalUri = request.uri; | |
const parsedPath = path.parse(originalUri); | |
if (parsedPath.ext === '') { | |
request.uri = '/index.html'; | |
let metaUrl = 'https://houseofradon.com'; |
This file contains hidden or 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
const fetchIndexHtmlAndCreateCloudFrontResponse = (url, metaTags, metaHeaders, callback) => { | |
downloadContent(url, (isOk, result, headers) => { | |
if (!isOk) { | |
console.log('Error fetching content:', result); | |
callback(false); | |
} else { | |
// We have <title>House of Radon</title> inside the actual index.html. We use that part to replace with actual metadata. | |
const finalBody = result.replace('<title>House of Radon</title>', metaTags); |
This file contains hidden or 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
const fetchMetaData = (url, callback) => { | |
downloadContent(url, (isOk, result, headers) => { | |
if (!isOk) { | |
console.log('Error fetching meta data:', result); | |
callback(false); | |
} else { | |
const metaData = JSON.parse(result); | |
let metaTags = ''; |
This file contains hidden or 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
const https = require('https'); | |
const zlib = require('zlib'); | |
const downloadContent = (url, callback) => { | |
https.get(url, (res) => { | |
let response; | |
let body = ''; | |
if (res.headers['content-encoding'] === 'gzip') { | |
response = res.pipe(zlib.createGunzip()); |