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

@codedazur/cdk-static-site

v3.0.0

Published

## Examples

Downloads

722

Readme

StaticSite

Examples

The minimum needed to get a StaticSite up and running is to provide the path to the directory that you want to deploy as your website.

new StaticSite({
  source: "./path/to/build/output",
});

With Excludes

If your output directory contains files you don't want to include in the deployment, you can exclude those with glob patterns.

new StaticSite({
  source: {
    directory: "./path/to/build/output",
    excludes: ["foo/*"],
  },
});

With Custom Domain Name

If you provide a domain name and an optional subdomain, Route53 and Certificate Manager will be used to create the necessary resources.

new StaticSite(this, "StaticSite", {
  // ...
  distribution: {
    domain: {
      name: "example.com",
      subdomain: "foo",
    },
  },
});

In the example above, a hosted zone will NOT be created automatically, but will instead be looked up in the AWS account using the domain name. In other words, given the example above, a hosted zone for the domain "example.com" is expected to be present in the account.

Alternatively, you can explicitly provide a reference to the hosted zone.

new StaticSite(this, "StaticSite", {
  // ...
  distribution: {
    domain: {
      // ...
      zone: new HostedZone(/* ... */),
      // zone: HostedZone.fromLookup(/* ... */),
      // zone: HostedZone.fromHostedZoneId(/* ... */),
    },
  },
});

With Basic Authentication

If you do not provide a password, a Secrets Manager secret will be created and its secret value used to verify the Authorization header using a CloudFront function. Keep in mind that editing the secret's value will not update the CloudFront function.

new StaticSite(this, "StaticSite", {
  // ...
  distribution: {
    authentication: {
      username: "username",
    },
  },
});

You can also provide your own secret. Once again, editing this secret will not automatically update the CloudFront function.

new StaticSite(this, "StaticSite", {
  // ...
  distribution: {
    authentication: {
      username: "username",
      password: new Secret(this, "PasswordSecret", {
        generateSecretString: { excludePunctuation: true },
      }),
    },
  },
});

Or, you could provide the password as a plain string, typically read from an environment variable.

WARNING: This method does NOT meet production security standards, even if the password is not hardcoded into the codebase, because it will result in the password string being readable in the CloudFormation template, which is uploaded to AWS. Use this approach with caution and only in cases where a leak is not considered problematic.

new StaticSite(this, "StaticSite", {
  // ...
  distribution: {
    authentication: {
      username: "username",
      password: process.env.PASSWORD,
    },
  },
});

With Explicit Cache Invalidation

By default, all routes will be flushed from the cache upon deployment. This is performed asynchronously using a step function, so that the deployment procedure does not hold until the invalidation is completed.

You can disable this behavior if you prefer an alternative means of invalidating the cache.

new StaticSite(this, "StaticSite", {
  // ...
  invalidateCache: false,
});

Or, you can provide the specific routes that you want to flush.

new StaticSite(this, "StaticSite", {
  // ...
  invalidateCache: ["/foo/*", "/bar/baz"],
});

With Custom Error Document

By default, the StaticSite will load a 404.html document when the requested path does not exist. If your application uses a different document, you can override it.

new StaticSite(this, "StaticSite", {
  // ...
  errorDocument: "error.html",
});