Making POST to Server Components (app/page.jsx) or passing data there other way #44428
Replies: 4 comments 4 replies
-
|
Are your pages in the |
Beta Was this translation helpful? Give feedback.
-
|
I have asked a related question on next-runtime discussion board, let's see if anything comes out of either one... |
Beta Was this translation helpful? Give feedback.
-
|
I made some progress. I figured I can create middleware to read request body I am able to just put it in the Next on the todo list is to figure out how I can pass this to |
Beta Was this translation helpful? Give feedback.
-
|
I found a ridiculous solution that abuses headers (and doesn't work anyway for large payloads since these have limits) https://clerk.dev/blog/nextjs-pass-value-from-middleware-to-api-routes-and-getserversideprops |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
So I am trying to do something Next.js is not created to do but I want to do it anyway ;).
I would love to embed some Next.js Server Components into a bigger application, which is written in Elixir/Phoenix. In order to do that, I am reverse-proxying the requests to Next.js server.
My Phoenix app already handles user authentication and sessions, so I only proxy to Next.js pages if the user is authenticated and has access to given page.
Then, I make a request back to Phoenix via API to fetch data, from the Server Component. That works, all great.
I am doing, however, a one extra HTTP request that I could avoid, if I was able to pass the payload required to render the server comonent with my proxied request. I had some ideas how to do it: stick the data into cookies, or headers before proxying, and I could read it. But I think both Cookies and Headers have size limit, so if I stick in a really large JSON payload in them, this will fail.
Now, the simplest way to do it would be for me in Next.js to accept POST requests to my routes, and I don't mean API routes but server component routes, and just read the payload from POST requests, that can be large.
It appears my Next.js apps does render my Server Components just fine over POST, but I have no idea how to read request body. Any tips?
Is this doable somehow? I don't see any way to make either pages or server components available over POST request, the documentation points to /api routes to accept the data but that's not what I want to do.
Any tips appreciated.
Beta Was this translation helpful? Give feedback.
All reactions