身份验证中间件仅适用于一条快速路线

时间:2020-07-20 23:52:49

标签: postgresql express

我正在尝试构建我的第一个PERN堆栈应用程序,但遇到一个烦人的问题,我无法弄清楚,其中我的身份验证中间件仅适用于一条路由。我尝试过创建简单的测试路线,但对那些都不起作用。中间件在邮递员上可以很好地工作,但在浏览器中只能用于axios.post请求。

\身份验证中间件

function [y] = model1y(x,u)
    statespace = ss(tf(250,[1 18 104 192]));
    l = length(statespace.C(:,1));
    y = zeros(l,1);

    for i = 1:l
        y = y + x(i) * statespace.C(i);
    end

    y = y + statespace.D * u;

end

\使用express.router()的路由

let auth = (req,res,next) => {
    const {token} = req.body;
  
    if(token === 'fish') {
        next();
    } else {
        res.status(403).json({message:'oops that was the wrong token!'});
    }
   
  
}
module.exports = auth;

\前端

router.get('/test' , auth, async function(req,res) {
    res.json({message:'this is a test'})
})

0 个答案:

没有答案