nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3.13k stars 625 forks source link

Nuxt content ignores cdnURL environment variable #2828

Closed tkgregory closed 2 weeks ago

tkgregory commented 2 weeks ago

Environment


Reproduction

This is the code deployed to AWS as described. The issue does not show itself when running locally.

https://github.com/tkgregory/bannerflex.git

Describe the bug

Nuxt includes a cdnURL configuration option to specify "An absolute URL to serve the public folder from (production-only)."

I don't think this option is respected in the Nuxt Content module.

Environment

I am deploying to AWS Lambda using the aws_lambda Nitro preset.

My lambda function has the environment variable: NUXT_APP_CDN_URL: https://d13yx967ab4do4.cloudfront.net/static/

Issue

My application is a single Vue component which reads a .yml file via Nuxt Content (view source).

<script lang="ts" setup>
const pricing = await queryContent('/pricing').findOne()
</script>

<template>
  <main>
    <p>Found {{ pricing.prices.length }} items in /pricing</p>
  </main>
</template>

Access the deployed application to see the following errors yourself here here.

Viewing source shows resources served from /static/ e.g. JS.

<link rel="prefetch" as="script" crossorigin href="https://d13yx967ab4do4.cloudfront.net/static/_nuxt/SPCSjI8F.js">

This makes me believe NUXT_APP_CDN_URL has taken effect for core application.

But Network tab shows 404 error fetching content:

https://d13yx967ab4do4.cloudfront.net/api/_content/query/BeNxk91izP.1730146068844.json?_params=%7B%22first%22:true,%22where%22:%5B%7B%22_path%22:%22%2Fpricing%22%7D%5D,%22sort%22:%5B%7B%22_stem%22:1,%22$numeric%22:true%7D%5D%7D

Error response body is {"message":"Not Found"}

Hence page fails to load and we see blank screen.

Expectation

I expect the page to load OK.

I can see this JSON file is available https://d13yx967ab4do4.cloudfront.net/static/api/_content/cache.1730146068844.json.

I may be doing something wrong here, but my suspicion is Nuxt Content is looking for the JSON file in the wrong location.

What else did I try?

Additional context

No response

Logs

No response

tkgregory commented 2 weeks ago

This was a misconfiguration of the Lambda function API gateway integration.

Needed to specify a path for the HTTP API of /{proxy+} instead of / to catch all paths