N
Nuxt5mo ago
Alex

Using Nuxt/Content works in nuxt dev but doesn't work after nuxt generate

Basically what the title says. I have a web app that is completely working when I do npm run dev but then when I run npm run generate and npx serve .output/public, I get a bunch of 404 errors. Any help would be greatly appreciated.
4 Replies
Alex
AlexOP5mo ago
const fetchData = async():Promise<BlogPost[]> => { const { data } = await useAsyncData('blogs',() => queryContent('/blog').find()) console.log(data) if(data.value && Array.isArray(data.value)) { return data.value.map((item:any) => ({ description: item.description, date: item.date, tags: item.tags, title: item.title, content: item })) as BlogPost[] } return [] } this is one of the ways I'm retrieving data btw
dwol
dwol5mo ago
You need ssr: true
Alex
AlexOP5mo ago
still doesnt work
export default defineNuxtConfig({
ssr: true,
css: [
'vuetify/lib/styles/main.sass',
'@mdi/font/css/materialdesignicons.min.css',
'@fortawesome/fontawesome-free/css/all.css'
],

build: {
transpile: ['vuetify']
},

vite: {
define: {
'process.env.DEBUG':false
}
},

devtools: { enabled: true },
modules: ['@nuxt/content'],

routeRules: {
'/': { prerender: true }
},

compatibilityDate: '2024-07-17'
})
export default defineNuxtConfig({
ssr: true,
css: [
'vuetify/lib/styles/main.sass',
'@mdi/font/css/materialdesignicons.min.css',
'@fortawesome/fontawesome-free/css/all.css'
],

build: {
transpile: ['vuetify']
},

vite: {
define: {
'process.env.DEBUG':false
}
},

devtools: { enabled: true },
modules: ['@nuxt/content'],

routeRules: {
'/': { prerender: true }
},

compatibilityDate: '2024-07-17'
})
thats my updated nuxt.config.ts
HTTP 7/18/2024 1:43:46 AM ::1 GET /api/_content/query/2Icfb2QCm3.1721281352225.json?_params=%7B%22where%22:%5B%7B%22_path%22:%22--REGEX+%2F^%5C%5C%2Fblog%2F%22%7D%5D,%22sort%22:%5B%7B%22_stem%22:1,%22$numeric%22:true%7D%5D%7D

HTTP 7/18/2024 1:43:46 AM ::1 Returned 404 in 2 ms

HTTP 7/18/2024 1:43:49 AM ::1 GET /api/_content/query/f8YtTx8L6u.1721281352225.json?_params=%7B%22first%22:true,%22where%22:%5B%7B%22_path%22:%22%2Fprojects%22%7D%5D,%22sort%22:%5B%7B%22_stem%22:1,%22$numeric%22:true%7D%5D%7D

HTTP 7/18/2024 1:43:49 AM ::1 Returned 404 in 2 ms
HTTP 7/18/2024 1:43:46 AM ::1 GET /api/_content/query/2Icfb2QCm3.1721281352225.json?_params=%7B%22where%22:%5B%7B%22_path%22:%22--REGEX+%2F^%5C%5C%2Fblog%2F%22%7D%5D,%22sort%22:%5B%7B%22_stem%22:1,%22$numeric%22:true%7D%5D%7D

HTTP 7/18/2024 1:43:46 AM ::1 Returned 404 in 2 ms

HTTP 7/18/2024 1:43:49 AM ::1 GET /api/_content/query/f8YtTx8L6u.1721281352225.json?_params=%7B%22first%22:true,%22where%22:%5B%7B%22_path%22:%22%2Fprojects%22%7D%5D,%22sort%22:%5B%7B%22_stem%22:1,%22$numeric%22:true%7D%5D%7D

HTTP 7/18/2024 1:43:49 AM ::1 Returned 404 in 2 ms
these are my errors btw
dwol
dwol5mo ago
maybe try adding prerender to the nitro config?
nitro: {
prerender: {
routes: [
'/some-route',
'/some-other-route'
],
}
},
nitro: {
prerender: {
routes: [
'/some-route',
'/some-other-route'
],
}
},
Want results from more Discord servers?
Add your server