Node.js 为什么nodejs没有';t将xhr设置为true?

Node.js 为什么nodejs没有';t将xhr设置为true?,node.js,Node.js,我有带express应用程序的NodeJ: const app: express.Application = express(); 我创建了一个api路由器: const api = express.Router(); const auth = express.Router(); auth.post('/login', (...) => { ... }); api.use('/auth', auth); app.use('/api', cors(), api); 在/api/auth/

我有带express应用程序的NodeJ:

const app: express.Application = express();
我创建了一个api路由器:

const api = express.Router();
const auth = express.Router();
auth.post('/login', (...) => { ... });
api.use('/auth', auth);
app.use('/api', cors(), api);
/api/auth/login
中,我将
req
对象的
xhr
属性设置为
false


为什么??我使用
axios
post
方法执行此请求,因此它是
xhr
请求。为什么nodejs不将
xhr
属性设置为true?有什么问题吗?

req.xhr
根据客户端的调用设置为true/false:
如果请求的X-request-With-header字段为“XMLHttpRequest”,则布尔属性为true,表示请求是由jQuery等客户端库发出的。
我需要做什么?我试着在《邮递员》中做这个请求,得到了同样的结果。我需要在nodejs应用程序中定义一些东西吗?我不明白为什么需要它成为一个xhr请求。文档中说,基本上只有在使用ajax发出请求时,xhr才会被设置为true。因为如果请求是xhr,我想发送一个错误,所以我将错误发送为json,如果不是,我将发送为原始htmlin。在这种情况下,您应该检查
req.accepts
以确定应该使用的格式: