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

Donovan
Hello everyone, I’m so glad to have discovered this awesome community. Thanks for creating it! This is my second post, and apologies for...
New
owaisqayum
I have a sample string sentence = "Hello, world ... 123 *** ^%&*())^% %%:>" From this string, I want to only keep the integers, ...
New
laiboonh
Hi all, I am trying to convince my team to use liveview over the current react. What are some of the points where one should consider us...
New
AstonJ
If a newbie asked you about Phoenix Contexts, how would you explain the basics to them? Feel free to be as concise or in-depth as you li...
New
IVR
Hi all, I’ve seen a number of related threads in the past, but I’d still be very curious to hear an up-to-date opinion on this topic. I...
New
marciol
Please, let me know if this kind of discussion already took place in another topic . Hi all, how do you consider if is better to build ...
New
und0ck3d
Hello everyone! A few days ago I’ve created a topic here about how people were creating CMSs with Elixir and Phoenix. I’ve been studying...
New
joeerl
I’m playing with Elixir - It’s fun. I think @rvirding does give Elixir courses these days. Re: files and database - when I given Erlang ...
New
Owens
Hello all, I am developing a new mobile app with Flutter frontend and Phoenix backend. The mobile app has real-time task management and c...
New
paulanthonywilson
I like Umbrella projects and pretty much always use them for personal Elixir stuff, especially Nerves things. But I don’t think this is ...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

We're in Beta

About us Mission Statement