h3
h3 copied to clipboard
`proxyRequest` does not use new req headers set `event.headers.set()`
Environment
Nitro v2.9.6
Node v20.12.2
Basic nuxt 3 project
Reproduction
https://stackblitz.com/edit/github-c51gfm?file=app.vue,server%2Fapi%2Fauth%2Flogin.post.ts,server%2Fapi%2F%5B...%5D.ts
Describe the bug
import {joinURL} from "ufo";
export default defineEventHandler((event) => {
const authCookie = getCookie(event, 'authorization')
const {proxyUrl} = useRuntimeConfig()
const path = event.path.replace(/^\/api\//, '')
const target = joinURL(proxyUrl, path)
event.headers.set('authorization', `Bearer ${authCookie}`) // does not work
Object.assign(event.node.req.headers, { Authorization: 'Bearer ' + authCookie}) // works
console.log(event.headers)
return proxyRequest(event, target, {
headers:{
authorization: `Bearer ${authCookie}` // works
}
})
})
event.headers.set() does not apply to proxyRequest, but other variants works well
Additional context
No response
Logs
No response
Any info?(
Hi, sorry for the late reply. Two-way sync is not possible today, unfortunately between event.node and event.node.req.headers
I would suggest to use ...event.node.req.headers in proxy request.
I will move this to more relevant place (h3)
Hi. With upcoming v2, two way sync will be possible (https://github.com/unjs/h3/pull/829)