{"id":77,"date":"2019-05-23T09:50:45","date_gmt":"2019-05-22T23:50:45","guid":{"rendered":"http:\/\/stuff.magicwilly.home\/?p=77"},"modified":"2019-05-23T09:50:45","modified_gmt":"2019-05-22T23:50:45","slug":"lambdaedge-add-index-html-to-request","status":"publish","type":"post","link":"http:\/\/stuff2.mygeekvps.net\/index.php\/2019\/05\/23\/lambdaedge-add-index-html-to-request\/","title":{"rendered":"Lambda@EDGE Add index.html to request"},"content":{"rendered":"<p>Node 8<\/p>\n<pre lang=\"javascript\" cssfile=\"none\">\n'use strict';\nexports.handler = (event, context, callback) => {\n    \/\/ Extract the request from the CloudFront event that is sent to Lambda@Edge\n    var request = event.Records[0].cf.request;\n    \/\/ Extract the URI from the request\n    var olduri = request.uri;\n    \/\/ Match any '\/' that occurs at the end of a URI. Replace it with a default index\n    var newuri = olduri.replace(\/\\\/$\/, '\\\/index.html');\n    \/\/ Log the URI as received by CloudFront and the new URI to be used to fetch from origin\n    console.log(\"Old URI: \" + olduri);\n    console.log(\"New URI: \" + newuri);\n    \/\/ Replace the received URI with the URI that includes the index page\n    request.uri = newuri;\n    \/\/ Return to CloudFront\n    return callback(null, request);\n};\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Node 8 &#8216;use strict&#8217;; exports.handler = (event, context, callback) => { \/\/ Extract the request from the CloudFront event that is sent to Lambda@Edge var request = event.Records[0].cf.request; \/\/ Extract the URI from the request var olduri = request.uri; \/\/<span class=\"ellipsis\">&hellip;<\/span><\/p>\n<div class=\"read-more\"><a href=\"http:\/\/stuff2.mygeekvps.net\/index.php\/2019\/05\/23\/lambdaedge-add-index-html-to-request\/\">Read more <span class=\"screen-reader-text\">Lambda@EDGE Add index.html to request<\/span><span class=\"meta-nav\"> &#8250;<\/span><\/a><\/div>\n<p><!-- end of .read-more --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-77","post","type-post","status-publish","format-standard","hentry","category-web"],"_links":{"self":[{"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/posts\/77","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/comments?post=77"}],"version-history":[{"count":0,"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/posts\/77\/revisions"}],"wp:attachment":[{"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/media?parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/categories?post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/tags?post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}