-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
209 additions
and
17 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.terraform | ||
*.tfstate* | ||
*.tfvars | ||
.idea | ||
.idea | ||
*.tfvars |
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
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 @@ | ||
1.1.7 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,52 @@ | ||
/** | ||
* | ||
* This is an example of a CloudFront Function to redirect www. access to non-www access. | ||
*/ | ||
function handler(event) { | ||
|
||
var requestPayload = event.request; | ||
var requestHost = requestPayload.headers['host'].value; | ||
var requestURI = requestPayload.uri; | ||
var requestQueryString = requestPayload.querystring; | ||
|
||
// if requestHost starts with www. | ||
if (requestHost.startsWith('www.')) { | ||
|
||
// generate new host without www. | ||
var newHost = requestHost.replace('www.', ''); | ||
|
||
// if requestURI does not start with / | ||
if (!requestURI.startsWith('/')) { | ||
// add / to requestURI | ||
requestURI = '/' + requestURI; | ||
} | ||
var redirectURL = newHost + requestURI; | ||
|
||
// convert querystring object to string | ||
var queryString = ''; | ||
for (var key in requestQueryString) { | ||
queryString += key + '=' + requestQueryString[key].value + '&'; | ||
} | ||
|
||
// if queryString is not empty | ||
if (queryString.length > 0) { | ||
// remove last & | ||
queryString = queryString.substring(0, queryString.length - 1); | ||
// add queryString to redirectURL | ||
redirectURL += '?' + queryString; | ||
} | ||
|
||
// return redirect | ||
return { | ||
statusCode: 301, | ||
statusDescription: 'Found', | ||
headers: { | ||
location: { | ||
value: 'http://' + redirectURL | ||
} | ||
} | ||
}; | ||
} | ||
|
||
return requestPayload; | ||
} |
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 @@ | ||
module "static-website" { | ||
source = "../../" | ||
name = "ashari.tech" | ||
custom_domain_provider = "ROUTE53" | ||
custom_domain_records = ["test", "www.test"] | ||
custom_domain_zone_id = var.custom_domain_zone_id | ||
cloudfront_function_file_path = "function.js" | ||
cloudfront_function_runtime = "cloudfront-js-1.0" | ||
cloudfront_function_type = "viewer-request" | ||
} |
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,3 @@ | ||
provider "aws" { | ||
region = "ap-southeast-1" | ||
} |
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,4 @@ | ||
variable "custom_domain_zone_id" { | ||
type = string | ||
description = "Domain Provider zone ID which custom domain is registered to" | ||
} |
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
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