axelson
Scenic Core Team
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!
- GitHub: GitHub - Main-Proxy/main_proxy · GitHub
- Hex package: main_proxy | Hex
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 ![]()
Trending in Announcing
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries.
offset-based pagination with...
New
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
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi all!
I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas.
You...
New
Hello
Published a new library - ProcessHub!
ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
This showed up on my feed.. anyone heard of it? Just hype?
Ox Alpha is a reasoning model designed for coding, sustained ag...
New
It’s not that it’s vocabulary is too advanced. It’s something worse.
I get lost trying to follow even a paragraph written by Claude. It’...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
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?
axelson
Supporting the Phoenix 1.7 update is proving fairly tricky because there’s a large update to how we sockets work under the hood. I have started the work to update but it isn’t complete yet (and hasn’t been pushed up to GitHub). MainProxy will be updated to support Phoenix 1.7 but I can’t make any promises as to when.
Here’s the issue to follow if you’re interested: Update `main_proxy` to support Phoenix 1.7 · Issue #28 · Main-Proxy/main_proxy · GitHub
LostKobrakai
Shouldn’t the new abstractions being put in to allow bandit ws support make it more trivial?
/cc @mtrudel
mtrudel
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.Cowboy2Handlerhas 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).
axelson
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)!
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
axelson
MainProxy 0.3.0 was just released today!
It adds support for Phoenix 1.7 (and drops support for earlier Phoenix versions). Thanks again to @mtrudel for helping on the upgrade. Here’s the full release notes:
https://github.com/Main-Proxy/main_proxy/blob/86cecf164b50369e09d83e85b340b3f9d72034b2/CHANGELOG.md#030---2023-03-05
metabren
Thanks for this @axelson! Any idea how to run this with Bandit?
axelson
MainProxy is currently very specific to Cowboy. I haven’t looked deeply at what would be required to add support for Bandit.
LostKobrakai
With the websocket handling abstracted in phoenix 1.7, is there still a need to interact with cowboy directly?
metabren
Thanks, me neither!
If I get some time I shall.