CDN Quick Start
Quick reference for CDN on this monorepo. Full guide: cdn-guide.md.
Enable CDN
Local / Docker (node-server)
NUXT_APP_CDN_URL=https://cdn.example.com npm run dev
Without NUXT_APP_CDN_URL, Nitro serves public/ from the origin (normal for local).
AWS (SAM test / production)
Public assets are not in the Lambda zip.
Test publishes to the shared CDN (https://d3sr1gndi209fc.cloudfront.net / shared-cdn-test-assets-…) at bucket root without --delete. Production uses the stack-owned bucket with --delete.
CD:
- Builds Nuxt with
app.cdnURLwhenNUXT_APP_CDN_URL/ shared export /AssetsCdnUrlis known - Stages
.output/<sysEnv>/server→ Lambda CodeUri - Stages
.output/<sysEnv>/public→infra/sam/.aws-sam/build-src/public - Syncs that public tree to the CDN bucket (
npm run sam:sync:dryrunor--sharedto preview)
NUXT_APP_CDN_URL=https://d3sr1gndi209fc.cloudfront.net npm run sam:build
npm run sam:deploy:test
nitro.serveStatic is false for aws_lambda. Origin hits to /favicon.ico / /_nuxt/* 302 to CloudFront via server/middleware/cdn.ts.
Use in Vue
<script setup lang="ts">
const { resolvePath, isEnabled } = useCdn();
const imageUrl = resolvePath('/i/portfolio/social-card.png');
</script>
<template>
<img :src="imageUrl" alt="Social card" />
</template>
Environment Variables
| Variable | Role |
|---|---|
NUXT_APP_CDN_URL |
Build-time app.cdnURL (absolute origin) |
NUXT_PUBLIC_CDN_URL |
Runtime override for public.cdnUrl |
SYS_ENV=test / production |
Selects aws_lambda + DynamoDB |
What’s Implemented
- ✅
app.cdnURL+ favicon rewrite when CDN is set - ✅ SAM stages
server/vspublic/separately - ✅ S3 sync after deploy (
sam-cd-deploy/sam-sync-public) - ✅ Lambda middleware 302 for leftover origin static GETs
- ✅
nitro.serveStatic: falseonaws_lambda
Need More Details?
See CDN Guide and SAM README.