Skip to the content.

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:

  1. Builds Nuxt with app.cdnURL when NUXT_APP_CDN_URL / shared export / AssetsCdnUrl is known
  2. Stages .output/<sysEnv>/server → Lambda CodeUri
  3. Stages .output/<sysEnv>/publicinfra/sam/.aws-sam/build-src/public
  4. Syncs that public tree to the CDN bucket (npm run sam:sync:dryrun or --shared to 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

Need More Details?

See CDN Guide and SAM README.