wolfiton

wolfiton

Can Phoenix api be integrated directly into NEXTJS?

Can the Phoenix api be used directly with NEXTJS without a node server?

If not does the node server add delays to requests?

Also the example folder that NEXTJS offer for supported servers so far

Thank you in advanced

Marked As Solved

peerreynders

peerreynders

SSR because I want to have offline support

SSR isn’t a prerequisite for offline support.

Offline support is accomplished via Service Workers. Now in the simplest case a Service Worker can cache responses which could be rendered pages but client side JavaScript can be cached as well. With an SPA you would tend to also use IndexedDB (with Promises) to stash some data for offline use.

Have a look at
Progressive Web Apps: Going Offline  |  Google for Developers
Gemini-powered solutions | Google for Developers
https://youtu.be/psB_Pjwhbxo?list=PLNYkxOF6rcIB2xHBZ7opgc2Mv009X87Hh

Also Liked

peerreynders

peerreynders

As far as I know server rendered pages are preferred for SEO. And while Google can process some JavaScript they only recently switched from Chrome 41 (2015) to 74.

This might be a good starting point for understanding some of the issues:
https://www.onely.com/blog/ultimate-guide-javascript-seo/

A PWA doesn’t need to be an (SSR) SPA (the App Shell Model created this confusion) - it is entirely possible to build a PWA where the page is rendered with EEx - but it’s the responsibility of the JS delivered with those pages to enable the PWA functionality on the browser end:

… that doesn’t automatically imply SPA. PWAs are supposed to extend “Progressive Enhancement”:

  1. Content is the foundation
  2. Markup is an Enhancement (HTML)
  3. Visual Design is an Enhancement (CSS)
  4. Interaction is an Enhancement (ECMAScript)
  5. Network is an Enhancement (Offline first)

https://love2dev.com/blog/pwa-spa/
https://love2dev.com/blog/yes-fast-food-frameworks-cost-too-much/
https://love2dev.com/blog/large-javascript-frameworks-are-like-fast-food-restaurants/

mhanberg

mhanberg

Expert LSP Core Team

I believe you will always need a server that will run the Next.js server (this is a Node app).

If you then want an API (Phoenix in this case), you will need to run your Phoenix server in addition to the Next.js server.

peerreynders

peerreynders

From:

def index(conn, _params) do
  component_path = "#{File.cwd!}/assets/js/HelloWorld.js"
  props = %{name: "Revelry"}

  { :safe, helloWorld } = ReactRender.render(component_path, props)

  render(conn, "index.html", helloWorldComponent: helloWorld)
end

And
https://github.com/revelrylabs/elixir_react_render/blob/master/lib/react_render.ex#L92-L110

So it looks to me that Node.js is rendering the React content but the phoenix controller is serving the rendered content - i.e. Node.js is rendering but not serving (but I haven’t looked much deeper in to it).

By the looks of things elixir-nodejs communicates with Node.js processes via ports.

Last Post!

Sleepful

Sleepful

You would need to use both, nextjs and phoenix as the API. You would call the phoenix API inside getServerSideProps… I guess. I found this related github repo GitHub - valo/phoenix_with_nextjs: An app template which used Phoenix for API and next.js for rendering frontend with server side rendering · GitHub

It sounds like a lot of work, and fun too.

I think ReactDOMServer is typically used with NodeJs because it is JavaScript code, React being a JavaScript library, so it integrates easily into NodeJs. I think there is nothing wrong with using ReactDOMServer to accomplish the same goals that NextJs seeks out to accomplish. I believe the difference is that NextJs seeks to make it really simple by handling all the SSR parts with high optimization and automagically for you (hydration, routing, client state).

CMIIW.

Where Next?

Popular in Questions Top

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
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
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
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44265 214
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement