# Deliver public assets through CDN for NestJS

## Summary
Cdn assets for a NestJS app on Ample. Verified on NestJS: a versioned, immutable-cached asset uploaded to a published bucket and served from the CDN URL. Build and start: npm install, nest build (TypeScript) then node dist/main.js on the node-22 template.

## Workload
Deliver public assets through CDN

## Prerequisites
- A NestJS project (npm install, nest build (TypeScript) then node dist/main.js on the node-22 template)
- A bucket from `ample bucket create` with credentials passed as encrypted S3_* environment variables
- An Ample account token with servers:write, buckets:read

## Resource Requirements
- primitive:compute
- primitive:cdn

## Infrastructure Requirements
- **Compute**: Apps run in isolated x86_64 Firecracker microVMs that auto-pause when idle and wake on request; sizes are the priced VM sizes.
- **CDN**: The CDN host serves objects from published buckets. It does not front app compute and is not a cache or key-value store.

## Tested Configuration
- **Template**: node-22
- **Runtime**: node
- **Size**: s-1vcpu-1gb
- **Install**: npm install
- **Build**: npm run build --if-present
- **Start**: npm run start

## Input Schema
```json
{  
  "additionalProperties": false,  
  "properties": {    
    "env": {      
      "description": "Encrypted environment variables",      
      "items": {        
        "pattern": "^[A-Z][A-Z0-9_]*=.*$",        
        "type": "string"      
      },      
      "maxItems": 50,      
      "type": "array"    
    },    
    "name": {      
      "description": "App name",      
      "maxLength": 63,      
      "minLength": 1,      
      "pattern": "^[a-z0-9-]+$",      
      "type": "string"    
    },    
    "path": {      
      "description": "Project directory or ample.toml service",      
      "maxLength": 512,      
      "minLength": 1,      
      "type": "string"    
    },    
    "release_command": {      
      "description": "Migration command run before activation",      
      "maxLength": 512,      
      "type": "string"    
    }  
  },  
  "required": [    
    "env",    
    "name",    
    "path"  
  ],  
  "type": "object" 
}
```

## Workflow Steps
1. **Build and start**: npm install, nest build (TypeScript) then node dist/main.js on the node-22 template; the server must bind 0.0.0.0 on PORT.
2. **Publish a bucket for public assets**: Publish only the asset bucket; upload versioned keys with an immutable Cache-Control header and build URLs from its public URL. Command: `ample bucket publish `
3. **Verify**: Fetch the live URL and /p/versioned-static-assets on the example; on failure read the build and runtime logs. Command: `ample logs --kind build`

## Limitations
- Verified on the node-22 template at s-1vcpu-1gb; other sizes and NestJS major versions are not verified.
- Region, compliance attestations and request-duration limits are unknown and not claimed.
- The CDN serves published-bucket objects only; cache rules, purge and TTL control are not verified.

## Cost Estimate
- **Currency**: USD
- **Monthly Amount**: 5.0
- **Basis**: size prices from pricing.toml (loaded by the API) at build revision 1ac5595375130d45290090e82ed0f554ccd45405-dirty

### Components
- **App Server**: size s-1vcpu-1gb, quantity 1.0, monthly amount 5.0

*Always-on monthly price of the tested sizes; apps auto-pause when idle. Buckets are allocation-priced per quota and not included.*

## Examples
- **NestJS pattern fixture**: Verified CDN assets on NestJS. Source Reference: tests/deploy-canaries/nestjs-patterns

## Success Checks
1. App responds on its public URL: **HTTP GET** on `/` expecting **ample canary nestjs patterns**.
2. Versioned-static-assets check from the example: **HTTP GET** on `/p/versioned-static-assets` expecting **see the pattern fixture checks**.

## Evidence Summary
- **Summary**: NestJS pattern fixture deployed on Ample; for this guide: a versioned, immutable-cached asset uploaded to a published bucket and served from the CDN URL.
- **Observed At**: 2026-09-21T02:34:39Z
- **Expires At**: 2027-03-20T02:34:39Z

## Next Actions
- **Browse the catalog index**: `GET /v1/catalog`
- **Search published recipes by intent, stack and constraints**: `POST /v1/catalog/search` (body: {"limit":5,"query":"Deliver public assets through CDN for NestJS"})
- **Prepare a side-effect-free deployment plan for an authorized project**: `POST /v1/catalog/plan` (body: {"inputs":{},"projectId":"","recipeId":"page:guides:nestjs:cdn-assets","recipeRevision":"r1"})
- **Read the existing agent authentication setup**: `GET /mcp/setup`
- **Browse NestJS**: `GET /v1/catalog/nodes/stack:framework-nestjs`
- **Browse Add CDN**: `GET /v1/catalog/nodes/intent:add-cdn`
- **Browse Versioned static assets**: `GET /v1/catalog/nodes/pattern:versioned-static-assets`
