bengro

bengro

Single Page Application deployment

Let’s assume I have a massive frontend codebase based on the Jam-stack. The existing backend will be replaced with Phoenix to leverage real-time features such as Sockets and Presence.

How would you deploy the frontend and the backend?
Would you deploy the frontend in the Erlang VM with some sort of webserver?
Would you deploy the backend in the Erlang VM, but the frontend in a “traditional” way (e.g. nginx)?

I appreciate any links to projects or opinions/thoughts.

Most Liked

vincer

vincer

I make heavy use of a similar stack and here are some solutions I’ve come across:

Backend options (option to store frontend with backend):

Gigalixir
A platform-as-a-service for Elixir. Very easy to use and I believe they have a free tier.
Their docs point to this helpful sample repo that includes assets that are compiled with Webpack. You can choose to store frontend here or not. I didn’t end up using them as I didn’t like the Python dependency.

Render.com
A sort of platform-as-a-service for all frameworks. No free tier, but the prices are reasonable. You basically just need to provide a build.sh file in your repo which handles building your app. If you wanted to store your frontend here, you would just need to add build instructions to the build.sh file. I tried their service and had no complaints, but in the end I found Kubernetes more flexible and easier for my use-case. I believe they use AWS or Google Cloud themselves.

Kubernetes on Google and Digital Ocean
This is what I use these days for all my projects (all are Vue 3 + Vite + Elixir apps). It’s the most productive recipe for me at the moment. I prefer keeping frontend and backend together as it simplifies deployment and testing. This approach is more complicated, but more flexible. I use Nginx in this setup. I maintain the details of this recipe in this repo.

Frontend options
If you want to host your frontend separately there many many options for that.

Free options
Render.com and now Digital Ocean let you host a few static frontends for free. The prices are very low even after the free tier.

Otherwise, there’s obviously Vercel, Netlify and soon Cloudflare Pages and probably a bunch of others.

Additional notes on storing frontend with backend
When storing the frontend with the backend, the Phoenix app serves the frontend content and assets. This Phoenix app may optionally also be behind something like Nginx. When storing the frontend separately with one of the providers listed above, the different services handle the serving of frontend assets for you mostly.

vincer

vincer

I have tried a few different structures and the one I like best is the one seen in this [folder](https://github.com/PotionApps/potionx/tree/main/packages/templates/src/project/potionx). Basically I keep all my Javascript apps in a folder called frontend in the same repository as the Elixir code and I serve the correct one based on the request’s domain or path. All requests go through the backend which routes the request to the right Javascript app. (Request → Elixir Backend → Controller → View → index.html containing the assets to a single page app)

I don’t think there is an established way of separating the two sides. At least if there is one, I haven’t found it yet. It all comes down to productivity. I’ve found that keeping the frontend apps and the backend together is the most productive for me in terms of ease of testing and speed of deployments.

In terms of configuring the client-side routing, I usually have Phoenix serve the right assets through a view like the one here. You can then use something like Cloudflare to serve the assets via CDN automatically if you’re worried about performance.

Your questions are definitely not dumb and I think many of us are still trying to find the best approach. There’s probaby no setup is going to suit everyone perfectly. I think you have to choose something that is most productive and least error-prone for you. In my case, I found managing only one project much much more productive than managing two projects.

Where Next?

Popular in Discussions Top

matthias_toepp
I’d love to hear what people think about Wisp, the new Gleam web framework started by Gleam’s primary creator Louis Pilfold. Gleam, alon...
New
owaisqayum
I have a sample string sentence = "Hello, world ... 123 *** ^%&*())^% %%:>" From this string, I want to only keep the integers, ...
New
WolfDan
After doing a port from a c++ library to my project in phoenix I’ve seen that I need a faster way to run this algorithm and I found this ...
New
arpan
Hello everyone :wave: Today I am very excited to announce a project that I have been working on for almost 3 months now. The project is...
New
fireproofsocks
This is more of a general question, but I’m wondering how other people in the community think about the pattern matching in function sign...
New
arcanemachine
https://nitter.net/josevalim/status/1744395345872683471 https://twitter.com/josevalim/status/1744395345872683471
New
nunobernardes99
Hi there Elixir friends :vulcan_salute: In a recent task I was on, I needed to check in two dates which of them is the maximum and which...
New
CharlesO
Erlang :list.nth simple, but 1 - based nth(1, [H|_]) -> H; nth(N, [_|T]) when N > 1 -> nth(N - 1, T). Elixir Enum.at … coo...
New
Ankhers
Just a little information upfront. Generally speaking, if I feel like I need to either break a pipe chain or use an anonymous function in...
New
eteeselink
Hi all, In the last days, two things happened: A blog post titled “They might never tell you it’s broken” made the rounds. It’s about ...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
New
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
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New

We're in Beta

About us Mission Statement