Subdomain in ExpressJS

Florent Source

Good morning everybody!

I'm currently attempting to make a full customized API with NodeJS (using Express) for my Wordpress website.

All was perfect until the authentification process.

I use JWT to auth users, but this process needs to call WP api from my custom API.

The request is as follow:

return new Promise( (resolve, reject) => {
    axios.post('https://pre-prod.mywebsite.fr/wp-json/jwt-auth/v1/token', {
        'username': username,
        'password': password
    })
        .then( (response) => {
            //console.log(response);
            resolve(response.data);
        })
        .catch( (error) => {
            console.log(error.response.data);
            let returnedError = [error.response.data, error.response.status];
            reject(returnedError);
        });
});

It works like a charm in local, but as soon as I upload it to my server, no more response are sent (502 bad gateway). I assume it don't really like to call itself, because here is the arborescence of my server:

  • pre-prod.api.mywebsite.fr -- Where all nodeJS files are

  • pre-prod.mywebsite.fr -- Where all WP files are

So I'm quite sure the app located in pre-prod.api.mywebsite.fr don't like to call itself but for path pre-prod.mywebsite.fr, and I really don't know how to link them without putting everything on the same folder...

node.jswordpressexpressjwt

Answers

comments powered by Disqus