| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Route requests to other Phoenix Endpoints or Plugs with WebSocket support.
This library is useful for Gigalixir, Render, Heroku or other deployments where only one web port is exposed.
Add MainProxy to your list of dependencies in mix.exs.
If you are running an umbrella project, adding MainProxy as a dependency at the root mix.exs won't work. Instead, either add it to one of your child apps or create a new child app solely for the proxy.
def deps do
[
{:main_proxy, "~> 0.1"},
]
endConfigure listening options for MainProxy:
config :main_proxy,
http: [port: 4080],
https: [port: 4443]Create a proxy module which configures backends:
defmodule MyApp.Proxy do
use MainProxy.Proxy
@impl MainProxy.Proxy
def backends do
[
%{
domain: "my-cool-app.com",
phoenix_endpoint: MyAppWeb.Endpoint
},
%{
domain: "members.my-cool-app.com",
phoenix_endpoint: MyAppMembersWeb.Endpoint
},
%{
verb: ~r/get/i,
path: ~r{^/main-proxy-plug-test$},
plug: MainProxy.Plug.Test,
opts: [1, 2, 3]
}
]
end
endBackends can also be configured via configuration:
config :main_proxy, http: [port: 4080], https: [port: 4443], backends: [ # ... ]But, it's not the recommended way.
Add above created proxy module to the supervision tree:
children = [
# ... other children
MyApp.Proxy,
]Configure all endpoints to not start a server in order to avoid endpoints bypassing MainProxy:
# ...
config :my_app, MyAppWeb.Endpoint, server: false
config :my_app_members, MyAppMembersWeb.Endpoint, server: falseIf you are running an umbrella project and you have chosen to add it as one of your child apps, then you will need to add your proxy child app (in this example named :my_proxy) to the releases specification in your umbrella's mix.exs file in order for MainProxy to work correctly in your releases. There's some more discussion about this in this ElixirForum post
deps: deps(),
releases: releases()
...
defp releases do
[
my_app: [
applications: [
my_proxy: :permanent
...
]
]
]
endmix run --no-halt
curl -i foo.com.127.0.0.1.xip.io:4080
curl -i localhost:4080This library is based on:
| Back | FazBrowse Home | New Git URL |