2

Hi I'm new to Nextjs and there are couple of things that I fail to understand.
Let say that I have a nextjs code acting as a front-end application and an express server (rest api) doing all the servery stuff.

The first question: Who servers the nextjs application?
Do I need to call the npm start command on my production server or can I server it with express static like a normal react project?

The next big mystery for me is Nextjs rebuilding process. Lets say my express server is updating some blog posts on database and Nextjs renders them:

// This function gets called at build time
export async function getStaticPaths() {
  const res = await fetch('https://.../posts')
  const posts = await res.json()
  const paths = posts.map((post) => ({
    params: { id: post.id },
  }))
  return { paths, fallback: false }
}

// This also gets called at build time
export async function getStaticProps({ params }) {
  const res = await fetch(`https://.../posts/${params.id}`)
  const post = await res.json()
  return { props: { post } }
}

Now this example from Nextjs website clearly says that these two functions are called at build time. Does this mean I have to rebuild my application every time backend updates something? and if the answer to this question is yes is there an automated solution for that?

isherwood
  • 58,414
  • 16
  • 114
  • 157
punjira
  • 818
  • 8
  • 21
  • 1
    Does this answer your second question: https://stackoverflow.com/questions/66036558/best-approach-for-an-app-with-150k-static-pages/66037031#66037031? – juliomalves Feb 17 '21 at 17:18
  • 1
    Regarding the first one, unless you're using `next export` you'll need to start the Next.js server. Either by running the built-in Next.js server with `next start` *OR* by running a [custom server](https://nextjs.org/docs/advanced-features/custom-server) with something like `NODE_ENV=production node server.js`. – juliomalves Feb 17 '21 at 17:21
  • 1
    @juliomalves Yes it does!! thanks for replying. – punjira Feb 17 '21 at 17:23

0 Answers0