-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated README for geoip-redirect package #1418
Open
porhkz
wants to merge
7
commits into
main
Choose a base branch
from
chore/DO-1777_update-readme-geoip-redirect
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d2c841f
Updated README
porhkz 9e2e327
Touched up README for conciseness
porhkz d3fd982
Fixed typo and added extra information
porhkz e24cf1d
Added diagram
porhkz 51ed8d1
Added where country code for request is pulled from
porhkz ab73492
Fixed typos in README
porhkz 69ea9ec
Tidy up extra lines in README
porhkz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,40 @@ | ||
# Geo-IP Redirect | ||
This library provides a construct which creates a Lambda@Edge functions to perform GeoIP redirects. | ||
|
||
These functions are intended to be added to an existing Cloudfront distribution | ||
![TypeScript version](https://img.shields.io/github/package-json/dependency-version/aligent/cdk-constructs/dev/typescript?filename=packages/geoip-redirect/package.json&color=red) ![AWS CDK version](https://img.shields.io/github/package-json/dependency-version/aligent/cdk-constructs/dev/aws-cdk?filename=packages/geoip-redirect/package.json) ![NPM version](https://img.shields.io/npm/v/%40aligent%2Fcdk-geoip-redirect?color=green) | ||
|
||
## Overview | ||
|
||
This library provides a construct which creates a Lambda@Edge function to perform GeoIP redirects. The Aligent Esbuild CDK construct is used to bundle the handler function from `handler/redirect.ts`. | ||
|
||
These functions are intended to be added to an existing Cloudfront distribution. When the Lambda@Edge function is triggered, the function is passed the CloudFrontRequestEvent. | ||
|
||
The Lambda@Edge function will check if the viewer's country code matches any supported regions. The country code from each request is pulled from the `cloudfront-viewer-country` header: | ||
- if they match, they are redirected to `${redirectURL}${countryCode.toLowerCase()}${request.uri}` | ||
- if they do not match, they are redirected to `${redirectURL}${DEFAULT_REGION.toLowerCase()}${request.uri}` | ||
|
||
The `DEFAULT_REGION` is set as an option in the Lambda@Edge handler code | ||
|
||
## Diagram | ||
|
||
![geoip lambda@edge diagram](docs/geoip-redirect.drawio.png) | ||
|
||
## Usage and Default Geo-IP Redirect options | ||
### `redirectHost` (string) | ||
- Base hostname used for redirects | ||
|
||
### `supportedRegionsExpression` (string) | ||
- Case-sensitive regular expression matching cloudfront-viewer-country | ||
|
||
### `defaultRegion` (string) | ||
- Fallback region code when viewer's country does not match the supported pattern | ||
|
||
## Example code | ||
When defining the Lambda@Edge function, this construct serves one default host to redirect too: | ||
``` | ||
define: { | ||
"process.env.REDIRECT_HOST": options.redirectHost, | ||
"process.env.SUPPORTED_REGIONS": | ||
options.supportedRegionsExpression, | ||
"process.env.DEFAULT_REGION": options.defaultRegion, | ||
}, | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor point but the formatting looks a bit funky here