Home > Enterprise >  is it possible to have a separate backend for next js application?
is it possible to have a separate backend for next js application?

Time:03-22

I am working on an app right now I just want to know is it possible to create a separate backend for the next js application because I want to connect react native app and web application with the same backend. Is it possible? and can I use getinitialprops and server-side props while having separate backend???

CodePudding user response:

Yes, you can. API Routes of Next Js can be use as backend, but it is optional.

getinitialprops, getServerSideProps, getStaticProps, are fetching methods of Next Js to handle the data and APIs in a headless way, so you can use any backend that expose an API.

Here are few ides for the arquitecture:

  • Next JS for webapp and Backend, React Native fetching Next Js API Routes
  • Next JS and react native in one project https://docs.expo.dev/guides/using-nextjs/ and any backend that you want to use
  • The last is project for each (Next, React Native, Backend)

CodePudding user response:

Backend is all about having the data. Nextjs has many fetching methods for both server side rendering and static generation. To fetch the data from backend, you can go with getStaticProps, getServerSideProps or getInitialProps. You can also fetch data locally by providing a simple json file within the application.

  • Related