vercel / micro

Asynchronous HTTP microservices
MIT License
10.59k stars 459 forks source link

How can I get headers from requests? #422

Closed NishidaRyu416 closed 4 years ago

NishidaRyu416 commented 4 years ago

I have tried the code below, reading the docs of node.js.

module.exports = async (req, res) => {
    const body = await json(req)
    console.log(req.getHeader("something"))
    return body
}
jamo commented 4 years ago

would this work:

req.headers[`something`]

https://nodejs.org/api/http.html#http_message_headers

NishidaRyu416 commented 4 years ago

Thanks for commenting. I tried it but it did not work properly either. In detail, the code gives me undefined.

timneutkens commented 4 years ago

You can log out req.headers etc. That would work. It could be that you're not sending the header though.