Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axios post request on / in proxy in create-react-app? #3311

Closed
gpbaculio opened this issue Oct 23, 2017 · 8 comments
Closed

Axios post request on / in proxy in create-react-app? #3311

gpbaculio opened this issue Oct 23, 2017 · 8 comments

Comments

@gpbaculio
Copy link

gpbaculio commented Oct 23, 2017

so I have this in my package.json proxy in create-react-app:

"proxy": "http://www.myapi.com"
my post requests works on other routes:

axios.post('/v1/users', { // http://www.myapi.com/v1/users
            email: email,
            password: password
        })
        .then((response) => { 
            this.setState((state, props) => ({
                registrationSuccess: true
            }));
        })
        .catch((error) => {
            this.setState((state, props) => ({
                registrationError: true
            }));
        });

but when I want to make post request on root, this works on postman, like on http://www.myapi.com it fails, this fails:

 axios.post('/', { // http://www.myapi.com
                email: email,
                password: password
            })

it will make post request on localhost:3000/, but I want to make post request on http://www.myapi.com proxy. help?

@gaearon
Copy link
Contributor

gaearon commented Nov 3, 2017

Please create a minimal reproducing example.

@OliCpg
Copy link

OliCpg commented Nov 22, 2017

Hi did you find any solution to this ? I am experiencing the same prolem without finding any solution nor explanation so far.

@Remoteski
Copy link

Having the same issue here as well. It seems like my axios.post requests are not utilizing the proxy config. My get requests work fine.

@gaearon
Copy link
Contributor

gaearon commented Jan 8, 2018

I'll close because there is no reproducing project. If you provide one we can take a look.

@gaearon gaearon closed this as completed Jan 8, 2018
@sidoshi
Copy link
Contributor

sidoshi commented Jan 9, 2018

I have reproduced this issue here. I am not sure if this is expected behaviour or a bug. Just to be clear, the issue is that the post requests to / don't get proxied to the specified server.

@gaearon
Copy link
Contributor

gaearon commented Jan 9, 2018

I see. I think this won't be a priority for us to fix, but if you send a PR we can take a look.

@sidoshi
Copy link
Contributor

sidoshi commented Jan 9, 2018

I tried to fix this. The best solution I could think of was to proxy all requests that do not have GET method. I assumed that all the requests to the webpack-dev-server will be using GET method. So its fine to use the proxy if specified and the method is not GET.

@gaearon
Copy link
Contributor

gaearon commented Jan 15, 2018

This is out in react-scripts@1.1.0! Please let us know if something doesn’t quite work.
https://github.com/facebookincubator/create-react-app/releases/tag/v1.1.0

@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants