Hello,
my Nextjs version is 13.2.1, earlier I was using SSR, now I am trying to utilize the ISR (getStaticProps()), and I have made some little changes in the DB and I am making an /pages/api call from the getStaticProps() but the updated content isn't updating when running npm run build and if I am trying npm run dev then after few mins it's reflecting but not when npm run build & npm run start
/pages/api/common/blogs/all.jsx:
// DB Config
import { connectDatabase, disconnectDatabaseConnection } from '../../../../DB/MongoDBQueries/connection'
// Queries
import { getAllDataByCondition } from '../../../../DB/MongoDBQueries/common'
// CONSTANTS
import { API_END_POINT_NOT_FOUND, DATABASE_CONNECTION_FAILED, SOMETHING_WENT_WRONG, UNSUCCESSFUL_MESSAGE } from '../../../../constants'
const handler = async (req, res) => {
// res.setHeader('Cache-Control', 's-maxage=86400')
let client
try {
client = await connectDatabase()
} catch (error) {
res.status(500).json({ message: DATABASE_CONNECTION_FAILED })
throw new Error(error)
}
try {
if (req.method === 'GET') {
try {
const blogsData = await getAllDataByCondition(client, 'blog', { isDeleted: false }, { publishedDate: -1 })
if (blogsData) {
return res.status(200).json({ payload: blogsData })
}
return res.status(400).json({ payload: UNSUCCESSFUL_MESSAGE })
} catch (error) {
console.log(' -----------------------------------------')
console.log('file: all.jsx:33 ~ handler ~ error:', error)
console.log(' -----------------------------------------')
return res.status(500).json({ payload: SOMETHING_WENT_WRONG })
}
}
return res.status(404).json({ payload: API_END_POINT_NOT_FOUND })
} catch (error) {
return res.status(500).json({ payload: SOMETHING_WENT_WRONG })
} finally {
await disconnectDatabaseConnection()
}
}
export default handler