axelson

axelson

Scenic Core Team

MainProxy - Run multiple Phoenix apps on one port

Note: previously the name of this library was MasterProxy

I just released version 0.2.0 of MainProxy. If you ever want to run multiple Phoenix Endpoints or Plugs from a single HTTP(S) port without manually writing a cowboy handler than MainProxy is for you!

To define your own proxy you add {:main_proxy, "~> 0.2"} to your deps, then create a proxy module:

defmodule MyApp.Proxy do
  use MainProxy.Proxy

  @impl MainProxy.Proxy
  def backends do
    [
      %{
        domain: "my-cool-app.com",
        phoenix_endpoint: MyCoolAppWeb.Endpoint
      },
      %{
        domain: "members.my-cool-app.com",
        phoenix_endpoint: MyAppMembersWeb.Endpoint
      }
    ]
  end
end

And then add MyApp.Proxy to your supervision tree in (usually in application.ex) and you can now serve multiple domains from one BEAM instance!

I’m interested in MainProxy because I run multiple applications from one BEAM instance with it:

And I’d like to give a big thanks to @jesse who created the initial version of the library :heart:

Most Liked

axelson

axelson

Scenic Core Team

Okay, a PR to update MainProxy to support Phoenix 1.7.0-rc.2 is now available! Please check it out at Update to support Phoenix 1.7 by axelson · Pull Request #31 · Main-Proxy/main_proxy · GitHub and let me know how it goes. I hope to cut a new release soon, although I’ll probably wait until Phoenix 1.7 is released since this update is not backwards compatible with earlier Phoenix versions.

@mtrudel Thanks for all the improvements you made to Phoenix 1.7 (e.g. websock)! :tada: It definitely makes MainProxy pretty much unnecessary (which I plan to note in its readme in the future). Although it does still seem a bit easier because MainProxy takes care of running a base plug for you since calling another Phoenix Endpoint from within a Phoenix Endpoint doesn’t work for websockets in my testing.

Edit: And also thanks for giving me pointers on the upgrade @mtrudel :heart:

mtrudel

mtrudel

Creator of Bandit

In theory: everything that comes into Phoenix now does so via either Plug or WebSock. Specifically, WebSocket upgrades are entirely mediated through Plug, and the resultant connections are managed via WebSock. This is why Phoenix.Endpoint.Cowboy2Handler has gone away; its only purpose was to shim Cowboy’s WebSocket support (both the process of upgrading & also managing the subsequent connections). Phoenix no longer exposes a Cowboy Handler implementation because it doesn’t need to.

The problem here is that MainProxy is (to my understanding) fundamentally concerned with routing to Cowboy handlers. To the extent that it seems to support ‘raw plugs’, this should be enough to do everything that Phoenix 1.7 needs. I can’t back that up with anything beyond a fairly broad architectural wave of the hand, however; I haven’t looked at MainProxy’s code in any really depth (though axelson and I have talked about this before).

All of this is also to say that the functionality of MainProxy (at least insofar as it proxies to Phoenix / Plug apps) could probably be subsumed by Plug.Router, since everything is just a Plug now. This would come with the side benefit of being functional on all servers, not just Cowboy (again, architectural handwaving abounds in this statement).

ErionS

ErionS

First off, thank you for the project. It is a default dep for me on all my umbrella projects.

Will this get updated to work with Phoenix 1.7 when it is released?

Where Next?

Popular in Announcing Top

tmbb
I’ve published the first version of my Makeup library. It’s a syntax highlighter for Elixir in the spirit of Pygments, Currently it highl...
New
mischov
import Meeseeks.CSS html = HTTPoison.get!("https://news.ycombinator.com/").body for story <- Meeseeks.all(html, css("tr.athing")) do...
New
pkrawat1
Presenting Aviacommerce, open source e-commerce platform in Elixir Aviacommerce is an open source e-commerce platform in Elixir. We at...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
deadtrickster
I’ve just released stable versions of my Prometheus Elixir libs: Elixir client [docs]; Ecto collector [docs]; Plugs instrumenter/Export...
New
mikehostetler
I’m excited to announce Jido, a framework providing foundational primitives for building autonomous agent systems in Elixir. While develo...
New
zorbash
I created Kitto a framework for dashboards inspired by Dashing. The distributed characteristics of Elixir and the low memory footprint...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
cjen07
parameterized pipe in elixir: |n> edit: negative index in |n> and mixed usage with |> are supported example: use ParamPipe ...
New

Other popular topics Top

skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement