H.Epstein
H.Epstein

Reputation: 731

http request with wrong domain

I'm using a post request in axios from my React JS front end to my Node JS backend server.

my front end runs on localhost:3000 while my backend runs on localhost:8080.

my front end code:

    foo = async () => {

    const data = {
        "data": "data",
    };

    const response = await axios.post('http:localhost:8080/createUser',data);
    console.log(response);
};

my backend code:

app.post("/createStripeConnectedAccount", async function (req, res) {

 const data = req.body;    
 // do some login here
 res('1')

});

but i get this error on my front end :

xhr.js:166 POST http://localhost:3000/localhost:8080/createStripeConnectedAccount 404 (Not Found)

for some reason the post request is send with both domains.

Upvotes: 0

Views: 197

Answers (1)

losik123
losik123

Reputation: 590

You have a typo in your url. Instead of:

const response = await axios.post('http:localhost:8080/createUser',data);

It should be:

const response = await axios.post('http://localhost:8080/createUser',data);

Upvotes: 1

Related Questions