@typren/adapter-cloudfront
v0.4.0
Published
CloudFront host adapter for typren: the canonical viewer-request function (directory-index rewrite + bare→slash canonicalization + KVS-backed redirect lookup, fail-open) and a `typren-cloudfront sync-redirects` CLI that diff-syncs @typren/core's redirects
Downloads
386
Maintainers
Readme
@typren/adapter-cloudfront
CloudFront host adapter for typren's redirects() (page
frontmatter aliases: string[]). Ships the canonical viewer-request function
for a static-export site on an S3 REST origin, and a CLI that diff-syncs the
redirect map into a CloudFront KeyValueStore.
Not IaC. This package never creates a bucket or a distribution — that's Terraform/CDK/SST territory.
Install
npm i -D @typren/adapter-cloudfrontQuick start
npx typren-cloudfront bootstrap --distribution-id E1234567890ABC
npx typren-cloudfront sync-redirects --store my-site-redirectsbootstrap is a one-time, guarded setup on a distribution that already
exists: it creates the KeyValueStore if needed, publishes the canonical
function, and attaches it to the default cache behavior. It refuses to
replace a different already-attached function unless you pass --force
(a blind replace has taken down a real site before — see the reference page).
sync-redirects is idempotent; re-run it whenever redirects change.
Security: an
.mjs/.js--mapfile passed tosync-redirectsis code and runs when loaded; a CI job executing it on freshly merged changes runs it with the job's AWS credentials. Use the.jsonmap form in CI, or require review on map changes.
Cost: a redirect change needs no CloudFront invalidation; the function reads the KeyValueStore at request time.
See the full reference for every export, CLI flag, required IAM action and error, and deploy-cloudfront for the end-to-end walkthrough.
License
Apache-2.0 — see LICENSE. It depends on @typren/core, which is
under the Functional Source License.
