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

feat(proxy): Add proxy support #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

calebdwilliams
Copy link

Adds basic proxy support similar to the most basic webpack-dev-server usage. This is pretty bare-bones right now, but can be amended to support the extended syntax. Should resolve #17.

@calebdwilliams
Copy link
Author

Because I needed this sooner rather than later, I released my fork as rollup-plugin-serve-proxy, but gave full attribution. I hope to finish porting the Webpack dev server syntax over to that package here eventually. Just a note for anyone else who needs this feature.

// If a proxy exists, forward the request to the appropriate server
if (proxy && proxy.destination) {
const { destination } = proxy
const newDestination = `${destination}${request.url}`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not well described in the read me how the final destination URL will be compiled.
Also logging the final destination URL before sending the request might help somebody.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with this, but wonder if the logging should be hidden behind a flag?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's entirely fair. Right now the behavior is that your example would work by going to http://httpbin.org/get/api. Is that not the desired behavior? Either way I will add some language to the README to clarify.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, the final url is http://httpbin.org/get/api, but shouldn't this result in 404 status code proxied instead of "Content Encoding Error".
I did not check the actual response cloning code to check what is actually happening.
Maybe I did not test properly.
I also used it to proxy to a complicated apache setup which has reverse proxy and somehow I could not get it working.
Maybe not all request headers from the original request are copied?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set up the proxy,but always return 404

Copy link

@pstanoev pstanoev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using it with:

proxy: {
  "api": "http://httpbin.org/get",
}

Results with "Content Encoding Error"

@calebdwilliams
Copy link
Author

Sorry I've been AWOL on this. I got busy on a couple different projects, but I fully intend to pick this back up as soon as possible.

@jfroffice
Copy link

any update on this feature ?

@loop-evgeny
Copy link

loop-evgeny commented Apr 14, 2021

I'm using rollup-plugin-serve-proxy - thanks very much for the fork - but it would be great to get this merged!

@thgh
Copy link
Owner

thgh commented Apr 14, 2021

Did I resolve the merge conflicts correctly?

@Symbianx
Copy link

Thanks for all the work into the plugin and this PR. What's the status on this? Would be really helpful for us

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Route api calls to backend
7 participants