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

About proxy #677

Closed
ignishub opened this issue Jul 17, 2017 · 2 comments
Closed

About proxy #677

ignishub opened this issue Jul 17, 2017 · 2 comments

Comments

@ignishub
Copy link

How can i make that my path (for example "localhost/some/api") will be processed by another go service?

@kataras
Copy link
Owner

kataras commented Jul 18, 2017

Hello @Viktor-Vasilev ,

You have two options here (same as with net/http) use a handler for a specific path or use a proxy server which will transfer all incoming requests to the target url.

Check https://github.com/kataras/iris/blob/master/core/host/proxy.go#L31,
you can use it as

// [...]
import "github.com/kataras/iris/core/host"
// [...]
// proxySrv := iris.New()
u, err := url.Parse("https://localhost:4444")
if err != nil {
	t.Fatalf("%v while parsing url", err)
}

p := host.ProxyHandler(u)
// [...]
app.Get("/some/api", iris.FromStd(p)) 

// or start a new whole proxy server:
go host.NewProxy("myproxy:3232", u).ListenAndServe()

These derives from net/http the only thing that Iris does, is some improvements on the url parsing and able to skip tls if your target is a loopback address (when testing).

For more options and advanced features you can take a look at other libraries, anything compatible with net/http is OK to being used inside iris too, therefore you don't have limitations.

@ignishub
Copy link
Author

Thank you!

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

No branches or pull requests

3 participants