NuxtContent in static site with changed baseURL
Having an issue with NuxtContent not finding the content files when I build out a static site. I have a layer as a base set of components and elements used across several apps. One of those components has:
<ContentDoc v-for="(item, index) in panel.items" :key="index" :path="path + item" :head="false" />
The panel.items array that is passed to this component is a prop received from the application that includes this layer. It is a list of the file names of the content to use.
The path is a computed property that is the pathname up to the last slash. (E.g., domain/foo/bar/index.html returns domain/foo/bar/).
In the application, I define the base URL for the application and content in the nuxt.config.ts:
const development = process.env.NODE_ENV !== 'production';
export default defineNuxtConfig({
app: {
baseURL: development ? '' : '/appname',
},
modules: ['@nuxt/eslint', '@nuxt/content'],
content: {
api: {
baseURL: development ? '/api/_content' : '/appname/api/_content',
},
},
extends: ['../base-layer'],
})
So I might pass a prop to my component with panel.items of something like ['item1'], while in my /content directory I have the corresponding item1.md. Running this locally does just fine, but after running generate, I see errors of the sort:
GET [domain]/appname/api/_content/query/UCtKQUGsT3.1724780426612.json?_params=%7B%22first%22:true,%22where%22:%5B%7B%22_path%22:%22%appname%2Fitem1%22%7D%5D,%22sort%22:%5B%7B%22_stem%22:1,%22$numeric%22:true%7D%5D%7D 404 (Not Found)
Debugging the generated app is more difficult as it is now in production mode. Any pointers to obvious errors or things to check would be appreciated.
0 Replies