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

Allows proxying paths of your application to different host #2477

wants to merge 2 commits into
base: master


None yet
4 participants
Copy link

arcturus commented Dec 28, 2018

↪️ Pull Request

This PR allows to pass extra parameters to the dev server to allow a specified path being proxied to a different host.

This is useful for development purposes, like proxy api calls (production, staging or testing) without having to enable CORS in a service that won't need to have CORS.

It adds to extra command line options --proxy-path where you specify which path from your dev server will be proxied, and --proxy-host the host that will receive the requests.

Found it not very intrusive, although I'm sure maintainers can guide me to make it easier to adapt to parcel philosophy.

💻 Examples

This feature has been requested before, #1562 or spectrum. Previously has been closed assuming that parcel can be used as a middleware for express. I end up writing this because my backend is in rust with

Also, planning to use in conjunction with to build the frontend even before I write the backend supporting graphql.

🚨 Test instructions

The typical usage will be like:
parcel <path to your sources> --proxy-path <path> --proxy-host <host>

This will proxy any request to http://localhost:1234/<path>* to <host>/<path>* in your parcel development server.

Using a public http echo service like:
parcel index.html --proxy-path /echo --proxy-host

Then you can access http://localhost:1234/echo?param1=1&param2=2

✔️ PR Todo

  • Added/updated unit tests for this change
  • Filled out test instructions (In case there aren't any unit tests)
  • Included links to related issues/PRs

Will need some help from maintainers to guide me on how to unit test this. Was planning to mock the module used for doing the http-proxy but didn't see anything like this in the unit tests.

arcturus and others added some commits Dec 13, 2018

Allows proxying paths of your application to different

Useful for development purposes.

This comment has been minimized.

Copy link

devongovett commented Dec 30, 2018

What do you think about configuring this in package.json rather than a CLI flag similar to how create-react-app does it?


This comment has been minimized.

Copy link

arcturus commented Jan 1, 2019

That's a fantastic idea, let me give it a try!


This comment has been minimized.

Copy link

arcturus commented Jan 1, 2019

@devongovett I've seen the proposed solution and looks feasible and very clean.

I've realised that with the proxy option in the package.json forces you to proxy the /api path which is very useful. What about the following idea, if proxy is a string, that's the host that will proxy /api/*. If proxy option is an object, we can expect path and host as a way of fine tuning how do you want to proxy.

Sounds good to you?


This comment has been minimized.

Copy link

domenkozar commented Jan 3, 2019

Would it be hard to support passing --proxy-path multiple times?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment