Skip to content

Commit

Permalink
Improving README doc examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ssennettau committed Feb 26, 2024
1 parent 52c092f commit b363ec9
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

CDK Construct to simplify using CloudFront to redirect entire domains or back-half stubs.

![GitHub Release](https://img.shields.io/github/v/release/ssennettau/CloudFrontRedirector-Construct) ![NPM Downloads](https://img.shields.io/npm/dw/cdk-cloudfront-redirector)


## Concept

Needs to redirect domains or building custom link shorteners is a common pattern required by many different solutions. This project simplifies using Amazon CloudFront with CloudFront Functions to rewrite the requests, forwarding users to another location.
Expand All @@ -10,6 +13,10 @@ Needs to redirect domains or building custom link shorteners is a common pattern

## Usage

This construct is able to either perform redirections for everything sent to a domain, or based on the back-half of the URL.

You might use this for something as simple as redirecting an unused `www` subdomain to a root apex, or for building your own link shortener service, similar to bit.ly.

For more details, check the auto-generated [API](API.md).

### Installation
Expand All @@ -23,22 +30,28 @@ npm install cdk-cloudfront-redirector
### Integrating

```typescript
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { RedirectionSite } from 'cdk-cloudfront-redirector';

export class DemoStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const redirect = new RedirectionSite(this, "RedirectionForWebsite", {
targetUrl: "https://ssennett.net/",
});

// Return outputs
new cdk.CfnOutput(this, "RedirectionUrl", { value: redirect.cfDistributionUrl })
}
}
// Basic Setup
const redirectBasic = new RedirectionSite(this, "RedirectionForWebsite", {
targetUrl: "https://ssennett.net/",
});

// Advanced Setup
const redirectAdvanced = new RedirectionSite(this, "RedirectionForWebsite", {
targetUrl: "https://github.com/ssennettau/CloudFrontRedirector-Construct",
pathRedirects: [
path: "/author",
destination: "https://ssennett.net/",
],
customDomain: {
domainName: "cfrc.cc",
hostedZone: "cfrc.cc",
}
});

// Return outputs
new cdk.CfnOutput(this, "RedirectionUrl", { value: redirectAdvanced.cfDistributionUrl });
```

## License
Expand Down

0 comments on commit b363ec9

Please sign in to comment.