# Deliver public assets through CDN for Express

Deliver public assets for a Express app through the Ample CDN. Publish a bucket with `ample bucket publish`, upload versioned assets with long-lived Cache-Control headers, and reference the bucket's public URL (`public_url` from `ample bucket publish`, https://<bucket>.<bucket domain>/<key>) from your pages. The CDN serves bucket objects; the app's own responses are still served by the app.

---

## What it runs on

- [Computeverified](/content/discover/primitive/compute/index.html)  
  Apps run in isolated x86_64 Firecracker microVMs; sizes are the priced VM sizes.

- [CDNverified](/content/discover/primitive/cdn/index.html)  
  A published bucket's objects are served from its public URL; set Cache-Control when uploading to control caching. App responses are served by the app.

---

## You need

- A bucket created with `ample bucket create` and published with `ample bucket publish` (its public URL is the CDN base)
- An S3 client in the app to upload assets under versioned keys
- An Ample account token with servers:write and buckets:write

---

## Exact tested configuration

buildnpm run build --if-present
    installnpm install
    runtimenode
    sizes-1vcpu-1gb
    startnpm run start
    templatenode-22

---

## Steps

1. **Publish the bucket.** Publishing makes objects readable at the CDN URL; keep private data in a separate, unpublished bucket.

```bash
    $ ample bucket publish <bucket-name>
    ```

2. **Upload versioned assets.** Use keys such as assets/<version>/file and set Cache-Control: public, max-age=31536000, immutable; change the version to invalidate.

3. **Reference the CDN URL.** Pass S3_PUBLIC_URL to the app and build asset URLs from it.

```bash
    $ ample deploy . --name <app-name> --public --env S3_PUBLIC_URL=... --env S3_ENDPOINT=... --env S3_REGION=... --env S3_BUCKET=... --env S3_ACCESS_KEY_ID=... --env S3_SECRET_ACCESS_KEY=...
    ```

4. **Verify delivery.** Fetch /asset-url for the asset URL, then fetch that URL: the CDN must return the asset.

5. **Verify.** Fetch the live URL and run the success checks below. On failure read the build log, then the runtime log, fix the cause and deploy again; do not blind-retry.

```bash
    $ ample logs <deployment_id> --kind build
    ```

---

## How it was checked

✓ asset URL resolves through the CDN· http get/asset-url → “/assets/”

---

## Evidence

1. November 5, 2026 · canary run  
   Express app uploaded a versioned, immutable-cached asset to a published bucket at startup; the CDN URL it returned served the asset publicly.

2. November 5, 2026 · canary run  
   ample bucket create issued credentials; PutObject and GetObject succeeded through the public S3 endpoint; publish exposed the object at its public URL with an ETag; unpublish and delete cleaned up.

---

## Tested examples

- **Express CDN assets canary.** Versioned asset uploaded to a published bucket and served from the CDN URL.

---

## What it doesn’t cover

- Verified on the node-22 template at s-1vcpu-1gb.
- Buckets speak the standard S3 API (PutObject and GetObject with path-style addressing are checked by the fixtures); `ample bucket upload-url` returns presigned upload URLs.
- Bucket credentials are passed as encrypted environment variables; the catalog never creates the bucket for you (use `ample bucket create`).
- Storage counts what you store, within your plan's allowance; the estimate below covers compute only.
- The CDN serves objects from published buckets; the app serves its own responses.
- Control caching with Cache-Control on upload and versioned asset keys.
