JSON服务器index.html

时间:2019-04-15 10:15:50

标签: json reactjs rest mocking json-server

我正在使用JSON服务器来模拟React应用程序的后端。我需要为 /index.html 路径应用自定义中间件,该路径用于应用程序检索CSRF令牌。我尝试了以下方法:

module.exports = (req, res, next) => {

console.log("middleware-csrf", req, res, next)

if (req.method === 'GET' && req.path === '/index.html') {
    res.header('X-CSRF-TOKEN', 'csrf-mock')
    res.type('html')
    res.status(200).end()
} else {
    next()
}

}

但是该请求仍返回JSON-Server自己的首页,而没有访问中间件。是否可以使用JSON-Server模拟 index.html 路径?

0 个答案:

没有答案