How to rebuild a NextJS project on production

Viewed 1075

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?

0 Answers
Related