Skip to content

feat(proxy): Add proxy support#40

Open
calebdwilliams wants to merge 2 commits into
thgh:masterfrom
calebdwilliams:proxy
Open

feat(proxy): Add proxy support#40
calebdwilliams wants to merge 2 commits into
thgh:masterfrom
calebdwilliams:proxy

Conversation

@calebdwilliams

Copy link
Copy Markdown

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
Copy Markdown
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.

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

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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.

Copy link
Copy Markdown

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
Copy Markdown

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

@pstanoev pstanoev left a comment

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown

any update on this feature ?

@emz00

emz00 commented Apr 14, 2021

Copy link
Copy Markdown

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

@thgh

thgh commented Apr 14, 2021

Copy link
Copy Markdown
Owner

Did I resolve the merge conflicts correctly?

@Symbianx

Copy link
Copy Markdown

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

@prantlf

prantlf commented Jan 3, 2026

Copy link
Copy Markdown

Proxy is included in #55 and #106 too.

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

8 participants