NextJs server side behaviour
Unanswered
Maine Coon posted this in #help-forum
Maine CoonOP
I have a website running on nextjs v12 & the content is fetched through strapi cms, as strapi cms used to go down due to high load which resulted in website downtime. So in order to solve this problem, I came up with the solution of serving static data through api (i'm using lambda function + s3 bucket to store static data for individual page) whenever strapi goes down, so that website keeps on running no matter if strapi is down. I have also added slack alerts when strapi goes down which is triggered in the lambda function itself. Below is the code samples for understanding :-
NextJs website :- pages/index.js
call to lambda function :-
lambda function :- responsible for returning static data which is stored in a file in s3 and i maintain a file which consist of down-pages path & send slack alert accordingly.
The issue is that even if strapi is not down i.e.
NextJs website :- pages/index.js
export default ({ data }) => {
return <Home data={data} />
}
export async function getServerSideProps(ctx) {
let homePageData;
homePageData = await getHomePageDataFromStrapi(); // fetches data using graphql from strapi
if (homePageData.notFound) {
// strapi is down, get data from s3 instead
homePageData = await getHomePageDataFromLambda(ctx.req.headers.host);
if (!homePageData) {
return { notFound: true };
}
}
return {props: { data: homePageData }}
}call to lambda function :-
function getHomePageDataFromLambda(host){
const res = await fetch('', {method:'POST',headers:{origin: host},body:JSON.stringify({filePath:'/homePageData.json'})})
const data = await res.json()
if (data.data) return data.data;
return null;
}lambda function :- responsible for returning static data which is stored in a file in s3 and i maintain a file which consist of down-pages path & send slack alert accordingly.
The issue is that even if strapi is not down i.e.
notFound: false, the lambda function gets called & i get slack alert (this only happens sometimes), so i'm confused why this is happening, is this could be a nextjs behvaiour? like it runs server side like a bot or a crawler & i don't really know why? Does someone have an explanation?