Search code examples
node.jsexpressaxiosfilemaker

Node.js first Api call succeeds, second Hostname/IP does not match certificate's altnames


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?


Solution

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