未发送自定义标头作为响应

时间:2020-06-15 16:56:06

标签: node.js express axios httpresponse custom-headers

我有一个登录用户的axios请求,但似乎无法在axios响应中看到前端的自定义标头。我在后端使用express设置它们,但没有收到错误,但是由于某种原因,响应消息未在axios中显示自定义标头。这是后端代码

router.post("/login", async (req, res) => {
    //confirm user is who they say they are 
    const successLogin = getUser(req.body)
    if(successLogin){
        //generate jwt token on successful login 
        const token = jwtToken(successLogin)



        // set response object fields
        res
        .cookie("token", token, { httpOnly: true })
        .set(
            {
                'Content-Type': 'application/xhtml+xml; charset=utf-8',
                'Authorization': 'Bearer ' + token
            })
        .send("logged in");
    }

    else{

        res
        .send('login failed')
    }


});

这是前端发生的事情

内容长度:“ 9”内容类型:“ application / xhtml + xml; charset = utf-8”

我正在发送的自定义标头未发送

0 个答案:

没有答案