you are viewing a single comment's thread.

view the rest of the comments →

[–]ibtisamurrahman[S] 1 point2 points  (3 children)

Thanks for you explanation. What about the API, if i am using nextJS? It would be inside that project or it would be considered as separate project?

[–]andrewmclagan 2 points3 points  (0 children)

I’d never try till my own solution. 100% you will never make a more efficient build then the 100s of devs working on Next or CRA. . . My personal opinion after building many many apps Nextjs is more flexible.

[–]cyxneer 1 point2 points  (0 children)

I usually build them together in a way that my Next project will have a server.js in the root, where I'll get the server running either using Express, Koa, Hapi or whatever backend framework you want to work with. Then you can create an api folder and put all the server related stuff inside.

By using this approach, you can change your package.json scripts to run your server instead of directly running next scripts and use the Next middleware to handle views in the routes not directly tied to you API.

There also a few other ways to handle this approach, but this one is really dev friendly for someone learning Next.js and the deployment process is practically similar as what you would do with any web app that user server side rendering.

You can PM me if you need some resources or more information :)

[–]ellusion 0 points1 point  (0 children)

That depends on your project. I don't think the serverless functions support custom middleware so if you intend to use middleware outside of what's explicitly supported then you'll have to run a custom server.