Next.js Discord

Discord Forum

Seeking Help with Serving JSON Data from MicroCMS in Next.js 14.1.4 via Amplify

Unanswered
Chu=Guevara posted this in #help-forum
Open in Discord
Hello,

I'm running Next.js version 14.1.4 with AWS Amplify. I'd like to fetch all data from MicroCMS during the build process, convert it to JSON, and then serve this JSON from api/works/route.ts. This setup is intended to facilitate tag searching and pagination.

What I've tried:

Using fs.writeFile:
I cannot write to storage in Amplify.

Storing in a variable:
The following method didn't work; it seems the variable gets reinitialized?

let cache;

!(async function () {
  cache = await microcms.getAllContents({ endpoint: 'a' });
})();

export default function GET(req: NextRequest) {
  // some filtering logic here
  return filteredCache;
}


I also tried placing JSON in S3 during the build, but I'm unsure about the costs involved and am looking for alternative methods.
Any guidance or suggestions would be greatly appreciated! Thank you.

1 Reply

I don't know much about MicroCMS
but should be a API...
So why do u want to fetch this data during build process and store, do u have a special use case for this?
Won't it be better to call the MicroCMS on page u want the data...