JAOdev
JAOdev

Reputation: 341

Axios without a full URL

I have a single web page application in the domain: sxxxcex-cxxfc.web.app

And the server, from which I will consume the API is at xx.x2.xx.74: 8000

To login with Axios, I do the following:

 const url='xx.x2.xx.74:8000/login/'

axios.get(url+user+"/"+password)
 .then((res: { data: any; }) => {
     setIngresar(false);
     const resquest = res.data;
     if(resquest=="invalid user"){
       console.log(resquest);
     }
     else{
        setItem("isRegistered", resquest[0].user);
     }
  }).catch((err: any) => {
    console.log(err);
    setIngresar(false)
  })

The full path of the GET method is

https://sxxxcex-cxxfc.web.app/xx.x2.xx.74:8000/login/theUSer/ThePassword

But it should be:

https: //xx.x2.xx.74: 8000 / login / theUSer / ThePassword

Could someone tell me how to send this last url without the sxxxcex-cxxfc.web.app?

Upvotes: 1

Views: 1506

Answers (1)

Kevin Shuguli
Kevin Shuguli

Reputation: 1750

It's because you didn't add "https://" in the url. So when you send request by axios, it try to find urls in the same domain. If you try your code in local, the url should be https://localhost:3000/xx.x2.xx.74.8000/login/theUSer/ThePassword. So you should add "https://" in front of url like this.

url = 'https://xx.x2.xx.74: 8000/login';
axios.get(url+user+"/"+password)
 .then((res: { data: any; }) => {
     setIngresar(false);
     const resquest = res.data;
     if(resquest=="invalid user"){
       console.log(resquest);
     }
     else{
        setItem("isRegistered", resquest[0].user);
     }
  }).catch((err: any) => {
    console.log(err);
    setIngresar(false)
  })

Upvotes: 1

Related Questions