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
  • I think the calls in the frontend are the same and are not the error here, I think the calls within the backend might be the issue, are both URLs in the node.js (express) application the same? maybe there is a typo there? – Lars Vonk Commented Nov 18, 2024 at 23:11
  • The first url is a session request, the second is a _find request. Unless I'm completely missing something here – Exterasmors Commented Nov 19, 2024 at 0:24
  • what happens when you .catch the error and then send a custom made error back so something like res.status(400).send('Something went wrong'); what do you get back then? – Lars Vonk Commented Nov 20, 2024 at 11:39
  • I was able to fix this yesterday but fot to answer my own question... after looking at the error, I noticed that my request was showing that it was coming from localhost:5157 instead of localhost:8080. I believe this was caused because i took the headers from the previous request by accident instead of creating a new header – Exterasmors Commented Nov 20, 2024 at 15:20
Add a comment  | 

1 Answer 1

Reset to default 1

After 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;

本文标签: