Tackleberry
Tackleberry
NNuxt
Created by Tackleberry on 11/7/2024 in #❓・help
API routes with route params not having types
I noticed my API routes only have typings if they do not contain a route param. Is this expected behavior? Is there a way to fix / improve it in the project? The docs don't say anything about it. Example:
// This api route is typed and will correctly infer Word[]
const words = await $fetch(`/api/words/all`)

// This api route is not typed, IDE can not infer response properties
const word = await $fetch(`/api/words/${route.params.wordId}`)
// This api route is typed and will correctly infer Word[]
const words = await $fetch(`/api/words/all`)

// This api route is not typed, IDE can not infer response properties
const word = await $fetch(`/api/words/${route.params.wordId}`)
5 replies
NNuxt
Created by Tackleberry on 10/24/2024 in #❓・help
Caching images generated by NuxtImage
I am experiencing a high server load since I started using NuxtImage, because images get generated from scratch all the time. Is there no way of caching images generated by nuxt image for a longer duration? It seems they are cached for 60 seconds only. I tried using something like
nitro: {
routeRules: {
'/_ipx/**': { swr: 600 },
}
},
nitro: {
routeRules: {
'/_ipx/**': { swr: 600 },
}
},
but this breaks images completely.
5 replies
NNuxt
Created by Tackleberry on 9/4/2024 in #❓・help
SWR vs maxStaleAge
How do swr and maxStaleAge in a defineCachedEventHandler play together? The docs say: swr: boolean Enable stale-while-revalidate behavior to serve a stale cached response while asynchronously revalidating it. Defaults to true. staleMaxAge: number Maximum age that a stale cache is valid, in seconds. If set to -1 a stale value will still be sent to the client while the cache updates in the background. Defaults to 0 (disabled). So swr defaults to true, and a stale cached response should be served. However, staleMaxAge defaults to 0, which means a stale cache is always invalid and will not be served to the client? This doesn't make any sense, does anyone have insight?
1 replies
NNuxt
Created by Tackleberry on 8/22/2024 in #❓・help
How to stop Nuxt from preloading in dev mode?
Dev mode preloads and applies all kinds of stylesheet that I don't want to be preloaded. I'm trying to get rid of that, but can't find a way. I relented to manipulating the head directly, but can't find a way to do that either! - useHead seems to have no way of removing elements. - I tried using the 'app:rendered' hook, but the renderResult.html only contains the body, and renderStyles() is only a function without any method to change the result. Is there no way to prevent nuxt from falsely including a bunch of stuff on the page that I don't want? 😦
1 replies
NNuxt
Created by Tackleberry on 8/13/2024 in #❓・help
e2e testing api routes: "setup" is not exported by "node_modules/unenv/runtime/mock/proxy.mjs"
I'm trying to test my nuxt api routes to make sure they work correctly. I've followed the setup guide from https://nuxt.com/docs/getting-started/testing#end-to-end-testing. But when I try to run the example test from https://nuxt.com/docs/getting-started/testing#setup-1 with vitest, I get the following error: RollupError: server/api/jobs.nuxt.test.ts (2:9): "setup" is not exported by "node_modules/unenv/runtime/mock/proxy.mjs", imported by "server/api/some-route.nuxt.test.ts" Am I missing something obvious here? Additional info: I used the installation command from the setup section, minus playwright-core since I want to use vitest as test runner: npm i --save-dev @nuxt/test-utils vitest @vue/test-utils happy-dom. Full error message:
FAIL server/api/jobs.nuxt.test.ts > My test
RollupError: server/api/jobs.nuxt.test.ts (2:9): "setup" is not exported by "node_modules/unenv/runtime/mock/proxy.mjs", imported by "server/api/some-route.nuxt.test.ts".
1: import { describe, test } from 'vitest'
2: import { setup, $fetch } from '@nuxt/test-utils/e2e'
^
3:
4: describe('My test', async () => {
FAIL server/api/jobs.nuxt.test.ts > My test
RollupError: server/api/jobs.nuxt.test.ts (2:9): "setup" is not exported by "node_modules/unenv/runtime/mock/proxy.mjs", imported by "server/api/some-route.nuxt.test.ts".
1: import { describe, test } from 'vitest'
2: import { setup, $fetch } from '@nuxt/test-utils/e2e'
^
3:
4: describe('My test', async () => {
2 replies