nitrojs / nitrojs/nitro

AWS Amplify preset doesn't support mixed render modes

Open
#3,540 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement v2
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

Describe the feature

The current preset does not support mixed render modes, e.g. Nuxt can deliver a SSR App with some prerendered pages. Amplify has issues to detect if a requested route is SSR or SSG, by default its calling SSR. If the route is SSG, this will result in a 500 error, because there is no "fallthrough". The preset itself support SSG, but only if the complete app i SSG, not mixed.

I think there are multiple possible solutions:

  1. Fallthrough: Serve statically all assets, if asset does not exists in bucket, the Server is requested
  2. Cloudfront Function / Lambda@Edge: A function with least possible overhead acts in front of the app, reads route config and pass request to right location
  3. SSR with long revalidation and warmup: Despite prerendering is configured, actually all routes are rendered with SWR and after build a warmup request triggers cache to have near SSG performance

Also look inside other presets for inspiration (Netlify / Vercel).

Just some ideation, not tested

export default defineNitroPreset({
  name: 'amplify-static-fallback',
  extends: 'aws-amplify',
  hooks: {
    // After Nitro has compiled server + static assets
    'nitro:compiled': async (nitro) => {
      const outDir = nitro.options.output.dir
      const manifestDir = join(outDir, '.amplify-hosting')
      const staticDir = nitro.options.output.publicDir

      // Ensure the folder exists
      await fs.mkdir(manifestDir, { recursive: true })

      // Deploy manifest: single static-first + SSR fallback
      const deployManifest = {
        version: 1,
        appRoot: outDir,
        staticAssets: {
          root: staticDir
        },
        routes: [
          {
            path: '/*',
            target: { kind: 'Static' },
            fallback: { kind: 'Compute', src: 'default' }
          }
        ]
      }

      const manifestPath = join(manifestDir, 'deploy-manifest.json')
      await fs.writeFile(manifestPath, JSON.stringify(deployManifest, null, 2))

      console.log('[Amplify Preset] Written static-first + fallback deploy-manifest.json')
    }
  }
})

Additional information
  • Would you be willing to help implement this feature?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the AWS Amplify preset and its nitro:compiled entry point, then compare the Netlify and Vercel presets for handling mixed SSR and SSG routes. Define and validate one approach that serves prerendered routes without a 500 while retaining SSR fallback; the issue does not name a specific test or file.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, nuxt, typescript
Domain
build-system, cloud
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.