javascript - 为什么 Chrome 发送两个 http 请求而 Firefox 发送一个?
问题描述
编辑:所以第二个响应肯定是 favicon.ico 问题,但为什么这发生在 chrome 而不是 firefox 中?
原文:我正在学习 node.js 的 express 并练习中间件的路由。我的问题是“/”路由正在通过,即使我没有发送请求并且我没有调用 next(); 在它之前的中间件中。此外,当我向“/”路由发送请求时,它会发送双重响应。它是在chrome而不是firefox中做到这一点的,所以有人可以解释一下区别吗?
const express = require('express');
const app = express();
app.use('/users', (req, res, next) => {
console.log('This handles /users route');
res.send('<h1>This handles /users route</h1>');
});
app.use('/', (req, res, next) => {
console.log('This handles / route');
res.send('<h1>This handles / route</h1>');
});
app.listen(3000);
如果我导航到 localhost:3000/users 页面显示正确的 html 但控制台日志:
- 这处理 /users 路由
- 这处理/路由
如果我导航到 localhost:3000/ 页面显示正确的 html 但控制台日志:
- 这处理/路由
- 这处理/路由
解决方案
默认情况下,Chrome 会请求网站 favicon.ico。像这样:
推荐阅读
- gitlab - 关于 Gitlab ECONNECT 问题的 Newman CLI
- sql - 将重复的行数据导入派生列
- python - 将列表的每个元素写入元组中作为 csv 的单独列
- google-sheets - 如何扩展现有的 Google Sheets UNIQUE SORT 公式以排除位于另一个工作表列上的项目
- python - 从包含特定值的 3D numpy 数组中删除所有行
- selenium - 网页抓取实现购物机器人的页面的最快方法
- java - 读取文本文件中的一个字符
- reactjs - 为什么我的 reactjs 项目加载无休止?
- android - 如何停止在 Android 中循环相同的回收器视图数据?
- django - Django Rest Framework Serializer 不打印嵌套关系