【发布时间】:2021-12-13 00:07:55
【问题描述】:
这是我的 nodejs 代码,与 https 网站完美配合。
app.use(cors({ origin: '*' }));
app.use(express.json())
app.use("/user", userRouter);
app.use("/mention", mentionRouter);
app.use("/request", requestRouter);
但问题是,如果我从任何 HTTP 站点发送请求,我会收到一条错误消息 TypeError: Failed to fetch 并且没有得到响应。这是我的前端代码。
const response = await fetch(WEB_URL + "mention", {
method: "POST",
body: JSON.stringify({
to: users,
text,
link: window.location.toString(),
}),
headers: {
"x-access-token": accessToken,
"Content-Type": "application/json",
},
});
我尝试了来自 Getting "TypeError: failed to fetch" when the request hasn't actually failed 的答案,但没有奏效。
【问题讨论】: