create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

Get user's real IP address using package.json proxy

Open shaysegev opened this issue 8 years ago • 4 comments

Is this a bug report?

Not sure

I love the use of proxy in package.json and it all works well, though I'd like to get the real user's IP address in the proxy request, though it always gets the local one 127.0.01 (which is understandable).

In Nginx, it is passed through a header such as x-forwarded-for.

I wonder if there's any implementation of passing the real IP address through the proxy?

Did you try recovering your dependencies?

Yes

Which terms did you search for in User Guide?

package.json proxy, react proxy ip address, react get ip address from proxy

Environment

Local environment

OS: Windows 10 Node: 8.11.2 Yarn: 1.5.1 npm: 5.6.0 Watchman: Not Found Xcode: N/A Android Studio: Not Found

Live environment

OS: Linux 4.4 Node: 10.4.0 Yarn: 1.7.0 npm: 6.1.0 Watchman: Not Found Xcode: N/A Android Studio: Not Found

Steps to Reproduce

No real steps here

Expected Behavior

Some documentation or implementation of how to get the user's IP address using the package.json proxy's feature.

Actual Behavior

Didn't find the IP address in the request (live server) Remote and local addresses were both 127.0.0.1

Reproducible Demo

Not relevant (imo)

Thanks for any help!

shaysegev avatar Sep 25 '18 21:09 shaysegev

You'll be able to define your own proxy middleware in version 2, which should be released soon. See here for details: https://github.com/facebook/create-react-app/pull/5073

iansu avatar Sep 25 '18 21:09 iansu

Thanks for your response @iansu , that would probably do.

shaysegev avatar Sep 25 '18 21:09 shaysegev

Yeah, you can access the headers through the request object in your middleware function. I'll close this since it's resolved in 2.0.

iansu avatar Sep 25 '18 22:09 iansu

This is already released under the next beta (just switch to the next tag).

Timer avatar Sep 25 '18 22:09 Timer