Hostname/IP does not match certificate's altnames #1678
-
I want to write a simple backend program using It looks like below: import express from "express";
import fetch from "node-fetch";
const app = express();
app.get("/api/get", (req, res) => {
const url = req.query["url"];
if (typeof url === "string")
fetch(url, {
headers: req.headers as Record<string, string>,
})
.then((r) => {
// do something
})
.catch((e) => {
// do something
});
else {
// do something
}
});
export const handler = app; I wanted it to be as transparent as possible, so I passed the request headers as-is to the target site. However the following error occurs:
The request url made by my website is {
host: 'localhost:5173',
connection: 'keep-alive',
'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1',
accept: '*/*',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
referer: 'http://localhost:5173/answer/2767440768',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9',
cookie: 'xxx',
'if-none-match': 'W/"4b0-/EkzfWBxtnLcu9kht55blTTaH9k"'
} When I removed the line where Another solution is to modify the host value before sending the request header: How can i resolve the error in case of sending request headers? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Forgive my stupid question. Remove the import express from "express";
import fetch from "node-fetch";
const app = express();
app.get("/api/get", (req, res) => {
const url = req.query["url"];
delete req.headers.host;
delete req.headers.referer;
if (typeof url === "string")
fetch(url, {
headers: req.headers as Record<string, string>,
})
.then((r) => {
// do something
})
.catch((e) => {
// do something
});
else {
// do something
}
});
export const handler = app; |
Beta Was this translation helpful? Give feedback.
Forgive my stupid question. Remove the
host
field andreferer
field before sending the request header.