豆包 PC 端软件 真就是个智障, 可别说自己是 AI 了!

xboxv:

提供了代码.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const app = express();
// 配置路由:当访问 /hello 时返回 'abc'
app.get("/hello", (req, res) => {
res.send("abc"); // 返回字符串 'abc'
});

// 使用 connect-history-api-fallback 中间件
app.use(
history({
index: "/index.html", // 指定回退的目标文件,默认为 /index.html
rewrites: [
// 自定义重写规则(可选)
{ from: /^\/api/, to: "/api/index.html" }, // 示例:对 /api 路径进行特殊处理
],
})
);

// 静态文件服务
app.use(express.static(__dirname + "/public"));

通义千问

根据你提供的代码,问题可能出在 connect-history-api-fallback 中间件的优先级上。connect-history-api-fallback 会拦截所有符合其规则的请求(例如非文件请求),并将它们重定向到指定的索引文件(如 /index.html )。如果它在路由定义之前被调用,那么 /hello 请求会被中间件捕获并重定向到 /index.html ,导致你的自定义路由无法生效。