npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@spencerbeggs/aws-cdk-domain-redirect

v1.4.2

Published

An AWS CDK construct that makes redirecting HTTP(S) requests to a different domain a breeze.

Downloads

4

Readme

aws-cdk-domain-redirect

Build Status Coverage Status Known Vulnerabilities

Route 53 is one of the cheapest, flexible and most powerful domain registrar and DNS provider around. And yet, there's no straightforward way to just redirect one domain to another like GoDaddy's trusty old domain forwarding feature. AWS Support offers a lackluster solution to the problem, which is to enable website hosting in S3 and redirect using bucket properties. But this prevents your site from using HTTPS — and who doesn't use HTTPS nowadays?

Setting up proper domain fowrarding on AWS involves a mess of CloudFront distributions, Lambda@Edge functions and Route 53 Alias records. Who has time for all that? If you are using AWS Cloud Development Kit to manage your infrastructure, this construct will wire it all together for your in just a couple lines of code.

Note: Lambda@Edge functions must be created in the us-east-1 region, which means that a stack using this constuct does, too.

Basic Usage

By default, this module just needs:

  1. the name of your hosted zone, e.g., source.com
  2. the ARN of a Certificate Manager certificate that supports your alias, by default {zoneName} and www.{zoneNane}
  3. the target URL you want to redirect traffic to
import { App, Stack, StackProps } from "@aws-cdk/core";
import { DomainRedirect } from "@spencerbeggs/aws-cdk-domain-redirect";

export class MyStack extends Stack {
	public constructor(scope: App, id: string, props?: StackProps) {
		super(scope, id, props);
		new DomainRedirect(this, "MyRedirects", {
			zoneName: "source.com",
			cert: "arn:aws:acm:us-east-1:62638843746:certificate/29789573-2b30-469f-cf...",
			target: "https://target.com",
		});
	}
}

You can also pass and array of options objects as the construct props if you want to setup fowrarding for multiple zones and configurations. Passing an array reduces the number of resources in your final template compared to instantiating multiple instances.

Advanced Usage

The configuration above is going to 301 redirect traffic from http(s)://source.com and http(s)://www.source.com to https://target.com. If you want to redirect domains other that the apex and www subdomain, just pass them as an array in the hostnames property:

new DomainRedirect(this, "MyRedirects", {
	zoneName: "source.com",
	cert: "arn:aws:acm:us-east-1:62638843746:certificate/29789573-2b30-469f-cf...",
	target: "https://target.com",
	hostnames: ["foo.source.com", "bar.source.com"],
});

The default configuration will preserve the request pathname and querystring when redirecting to the target. You can selectively control this behavior with the preserve property:

new DomainRedirect(this, "MyRedirects", {
	zoneName: "source.com",
	cert: "arn:aws:acm:us-east-1:62638843746:certificate/29789573-2b30-469f-cf...",
	target: "https://target.com",
	// you can also disable both with preserve: false
	preserve: {
		path: true,
		query: false,
	},
});

You can also pass a Certificate construct as the cert property. The zoneName property can also be a HostedZone construct or an IHostedZone, just be aware that you need to look them up by zoneName. Types are bundled with the module.