React form prepend the base url

Viewed 62

How I can stop prepending the default URL when using Axios post or fetch

const onSubmit = (event: any) => {
event.preventDefault();
axios.post(`/auth/login`, formData)

In browser devtools the error:

POST http://localhost:3000/localhost:4000/auth/login 404 (Not Found)

In app.tsx, i've made axios base url to the backend API

axios.defaults.baseUrl = 'http://localhost:4000';

Form is setup like this:

<form className={classes.form} onSubmit={onSubmit}>
... material ui elements
</form>

There is no place everywhere in the codebase where I've put http://localhost:3000

BR,

0 Answers
Related