Open jonkri opened 1 month ago
I've uploaded a reproduction.
Just run the backend (see Additional context above) with node index.js
, run the frontend with npm run dev
, and visit http://localhost:3000.
This code in app.vue
works:
const test = (await useFetch("/api/test")).data;
This code in app.vue
server-side renders the code correctly but then produces a 500 Internal Server Error page due to test
being null
:
const test = (await useApi("/test")).data;
@enkot: Do you happen to see anything in /server/api/[...].ts
that conflicts with nuxt-open-fetch's use[Client] function?
import { defineEventHandler, H3Event, parseCookies, setCookie } from "h3";
import { joinURL } from "ufo";
export default defineEventHandler(async (event: H3Event) => {
const cookies = parseCookies(event),
{ proxyUrl } = useRuntimeConfig(),
target = joinURL(proxyUrl, event.path),
token = cookies?.token;
if (token !== undefined && token !== "") {
setCookie(event, "token", token);
}
return proxyRequest(event, target);
});
I looked into this some more and have arrived at a simpler reproduction.
I'm no longer using a server route, only routeRules
.
nuxt.config.ts
:
export default defineNuxtConfig({
// ...
modules: ["nuxt-open-fetch"],
openFetch: {
clients: {
api: {
baseURL: "/api",
schema: "schema.json",
},
},
},
routeRules: {
"/api/**": { proxy: "http://localhost:3001/api/**" },
}
});
App.vue
:
// const test = (await useFetch("/api/test")).data; // Works ✅
const test = (await useApi("/test")).data; // Doesn't work ❌
To reproduce:
$ unzip test.zip
In one terminal:
$ cd test
$ node index.js
In another terminal:
$ cd test
$ npm install
Visit http://localhost:3000/ and refresh the page. It will briefly display “test”, then it will display “$setup.test is null”.
Same problem, all response values are undefined
Environment
Darwin
v20.10.0
3.13.0
3.13.0
2.9.7
npm@10.2.3
-
compatibilityDate
,devtools
,modules
,openFetch
,runtimeConfig
nuxt-open-fetch@0.9.1
-
Reproduction
test.zip
Describe the bug
use[Client] produces a
null
value in itsdata
property when a Nuxt server route is used.useFetch
doesn't.Additional context
This backend can be used when running the reproduction:
Logs
No response