Gradually upgrading, phoenix → nex using pluggable routes

I’d like to upgrade my Phoenix app to Nex.
Both of these packages rely on plug as middleware.
Maybe a plug mechanism can help to add new routes in Nex, alongside the earlier Phoenix app.
I imagine this is going to be a common use case.

As is, these seem related:

Mainly asking for guidance from @zhenfeng-zhu, and also opening this discussion to track my progress in my own codebase. (for the mods: we need a category of “Elixir Framework Forums / Nex”!)

As a nearly-real example, my blog is already in Phoenix. I’d like to build commenting using HTMX tags and dedicated Nex file-based routing. Here are two generic processes I can imagine.

Approach 1: Nex-in-Phoenix

  1. run mix nex.new nex_app
  2. run rsync -a nex_app/lib/* phoenix_app/lib/
  3. start the nex_app inside of the phoenix_app.
  4. inside the phoenix router, forward "/nex", to: NexApp.Endpoint
  5. gradually move logic to nex_app using file routes.

Approach 2: Phoenix-in-Nex

  1. run mix nex.new nex_app
  2. run rsync -a phoenix_app/lib/* nex_app/lib/
  3. start the phoenix_app inside of the nex_app
  4. somehow? forward to the phoenix routes from nex? is this possible?
  5. absorb the phoenix logic into Nex’s file routes.

Do they have to be running in the same supervision tree? If the goal is to gradually port from Phoenix to Nex, I would probably just run both applications on different ports and proxy them with nginx or caddy. Then I could port one route at a time from the Phoenix app to the Nex app and without needing to keep Phoenix idioms around in the new Nex code. If you’re using postgres for your db, you’d just need to make sure both applications have the same db user credentials, and any service or data layer code could be pulled out into a local hex package (:path dep in mix.exs) if you don’t want to copy that code between both apps.

Honestly though, if the project isn’t too large, it might be easier to just do the full port all at once and maintain the existing Phoenix app until the Nex version is ready for prod. I guess it would depend on how the project is set up and if it’s easy to separate logic by individual routes or not. Food for thought anyway. :slight_smile:

1 Like