Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxyRequest does not use new req headers set event.headers.set() #763

Open
lammerfalcon opened this issue May 27, 2024 · 3 comments
Open

Comments

@lammerfalcon
Copy link

lammerfalcon commented May 27, 2024

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

@lammerfalcon
Copy link
Author

Any info?(

@pi0
Copy link
Member

pi0 commented May 31, 2024

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)

@pi0 pi0 transferred this issue from nitrojs/nitro May 31, 2024
@pi0 pi0 changed the title proxyRequest does not see new headers after event.headers.set() proxyRequest does not use new req headers set event.headers.set() May 31, 2024
@pi0
Copy link
Member

pi0 commented Jul 18, 2024

Hi. With upcoming v2, two way sync will be possible (#829)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants