admin管理员组文章数量:1431895
I've seen many posts about this, and how this means that you need to fix your certs.
I'm a little confused as to how these certs work in my context. I have 2 Api calls on my React app to an node.js server; both are currently running on separate localhost ports.
The first Api call that is an attempt to login to and receive an auth token from Filemaker Pro. This runs successfully, and i get an auth token.
The second Api call, is meant to make a query on this database using that auth token, and receive a list of values back.
This fails giving me this AxiosError: Hostname/IP does not match certificate's altnames: Host: localhost. is not in the cert's altnames: DNS:xxx
Because the first request works, I would assume this is actually an issue with my code, but everything else makes me believe otherwise. I've also tried temporarily using rejectUnauthorized = false
to try to circumvent this.
App
async function fetchApi(){
const encodedString = Buffer.from(input).toString('base64');
const headerString = "Basic " + encodedString;
const data = {
headers:{
'Content-Type': 'application/json',
'Origin': "",
'Authorization': headerString
},
};
await axios.post("http://localhost:8080/login", data)
.then(function(response) {
const token = response.data.response.token;
authToken = token;
fetchScheduableJobs();
})
.catch(function (error) {
console.log(error.toJSON());
});;
}
async function fetchScheduableJobs(){
const query = {
"query":[
{"Go ahead date": "10/01/2024...10/31/2024"}],
"limit": "10000"
}
const data = {
headers:{
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + authToken
}
};
await axios.post("http://localhost:8080/scheduleJobs", query, data)
.then(function(response){
console.log(response);
})
.catch(function (error) {
console.log(error.toJSON());
});
Node.js
app.post("/login", async (req, res) => {
await axios.post("https://xxx/fmi/data/vLatest/databases/xxx/sessions", {} ,req.body)
.then(function(response) {
res.send(response.data);
})
.catch(e => {
console.log(e);
});
});
app.post("/scheduleJobs", async (req, res) => {
const body = req.body;
const headers = req.headers;
await axios.post("https://xxx/fmi/data/vLatest/databases/xxxx/layouts/xxx/_find",
body
,{headers})
.then(function(response) {
res.send(response.data);
})
});
What makes me even more confused, is that I have a Python script that already does exactly this, with no problems.
Why does one call work but the other doesn't?
I've seen many posts about this, and how this means that you need to fix your certs.
I'm a little confused as to how these certs work in my context. I have 2 Api calls on my React app to an node.js server; both are currently running on separate localhost ports.
The first Api call that is an attempt to login to and receive an auth token from Filemaker Pro. This runs successfully, and i get an auth token.
The second Api call, is meant to make a query on this database using that auth token, and receive a list of values back.
This fails giving me this AxiosError: Hostname/IP does not match certificate's altnames: Host: localhost. is not in the cert's altnames: DNS:xxx
Because the first request works, I would assume this is actually an issue with my code, but everything else makes me believe otherwise. I've also tried temporarily using rejectUnauthorized = false
to try to circumvent this.
App
async function fetchApi(){
const encodedString = Buffer.from(input).toString('base64');
const headerString = "Basic " + encodedString;
const data = {
headers:{
'Content-Type': 'application/json',
'Origin': "",
'Authorization': headerString
},
};
await axios.post("http://localhost:8080/login", data)
.then(function(response) {
const token = response.data.response.token;
authToken = token;
fetchScheduableJobs();
})
.catch(function (error) {
console.log(error.toJSON());
});;
}
async function fetchScheduableJobs(){
const query = {
"query":[
{"Go ahead date": "10/01/2024...10/31/2024"}],
"limit": "10000"
}
const data = {
headers:{
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + authToken
}
};
await axios.post("http://localhost:8080/scheduleJobs", query, data)
.then(function(response){
console.log(response);
})
.catch(function (error) {
console.log(error.toJSON());
});
Node.js
app.post("/login", async (req, res) => {
await axios.post("https://xxx/fmi/data/vLatest/databases/xxx/sessions", {} ,req.body)
.then(function(response) {
res.send(response.data);
})
.catch(e => {
console.log(e);
});
});
app.post("/scheduleJobs", async (req, res) => {
const body = req.body;
const headers = req.headers;
await axios.post("https://xxx/fmi/data/vLatest/databases/xxxx/layouts/xxx/_find",
body
,{headers})
.then(function(response) {
res.send(response.data);
})
});
What makes me even more confused, is that I have a Python script that already does exactly this, with no problems.
Why does one call work but the other doesn't?
Share Improve this question asked Nov 18, 2024 at 21:42 ExterasmorsExterasmors 133 bronze badges 4 |1 Answer
Reset to default 1After playing around with things and spitting out hundred of console logs.
I realized that this is the culprit in the server...
const headers = req.headers;
Instead of creating a new header, I was taking the header of the previous request and trying to use that in my new request, thus causing this error
Instead now I am doing this
const headers = req.body.headers;
本文标签:
版权声明:本文标题:express - Node.js first Api call succeeds, second HostnameIP does not match certificate's altnames - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745592451a2665281.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
.catch
the error and then send a custom made error back so something likeres.status(400).send('Something went wrong');
what do you get back then? – Lars Vonk Commented Nov 20, 2024 at 11:39