C#C
C#3y ago
10 replies
mylaff

❔ Web stack and connecting C# backend w/ Next.js frontend

Hey! Recently been learning frontend with React and Next.js, so far so good, however, for my project which is somewhat complex, I think I need a separate backend than the options that Next.js itself provides. Backend REST API and realtime SignalR handles data streamline for the applicaiton. Sounds good on paper, however I'm not entirely sure that it is that simple and more than that I lack understanding how the entire thing will be working, connecting and hosting.

For me as for someone new into that web tech, it looks like this:
I have separate REST API C# project (including SignalR endpoints ig, I don't see point of moving SignalR few endpoints into separate project, however it might be just me), which is being ran in container alongside with other container, running my Next.js frontend, and frontend just uses HTTP requests for API when they are required. This should not trigger CORS as far as I understand, since both things will be ran on the same server, behind the same webserver and URL. But here's the thing, REST API for sure must have an authorization and authentication on barely every endpoint it exposes. And I don't seem to get how do I do authorization in the way that we can then store it and use on frontend app. Is it that simple as calling authorization endpoints at REST API from serverside rendered (or even client side rendered) components and then calling some cookie/idb methods on the Next.js side to mount that data into users browser?
Problem is that I can not imagine the whole image in my head and mentally connect things, decide what techs and interactions I have to learn.

The things I don't fully understand:
- Does Next.js comes with somewhat builtin webserver for production or do I need ngingx to proxy requests? It seems like I do, because I have to route requests between REST App, and frontend App (or am I overlooking something)?
- Already mentioned authorization problem.

I will be really grateful for help.
Was this page helpful?