c4lliope

c4lliope

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.

Most Liked

GrammAcc

GrammAcc

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:

Where Next?

Popular in Questions Top

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
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement