Here is my nodejs code that works perfectly with https site.
app.use(cors({ origin: '*' }));
app.use(express.json())
app.use("/user", userRouter);
app.use("/mention", mentionRouter);
app.use("/request", requestRouter);
But the problem is if I send the request from any HTTP site, I get an error saying TypeError: Failed to fetch
and get no response. Here is my frontend code.
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",
},
});
I tried answers from this Getting "TypeError: failed to fetch" when the request hasn't actually failed but not working.