I want to create an application where the frontend is in Next.js, fetching data from an API and displaying it on the page. The API will be in Strapi and will be hosted on the same server as the Next.js application. The idea is to have the API routes and admin routes handled by Strapi, while all other routes are managed by Next.js. Inside Next.js, I will fetch data using fetch on /api/(collection)/(id)*. Is this possible? Does it make sense? If it is possible, in what form? I have considered alternatives, but I have found Next.js + Strapi to be the most suitable in terms of functionality.
I am familiar with the option where I host both applications on different hosting and get the data from the API URL from the following and implemented it in detail, but it would be very convenient to understand what it is, which I wrote about above, so that /admin would be a convenient CMS for the client was separated by logic from the next one and had to not maintain two separate hostings for the sake of it
What you want would mean that Strapi is powered by your Next.js app, which is currently not possible (and probably will never be). You could probably use Next config redirect to redirect all /admin requests to Strapi, but that won't change your need to keep one single server for both your app and Strapi.
Have you tried considering using a monorepo tool like turborepo , that would help you keep all your codebase strongly binded ?
Maybe you could try to use Koa (the internal Strapi web framework) to run a React app from your Strapi server, but not sure I could work with Next.js, and anyways that's a shady path to follow IMHO.
I'm currently following the development of PayloadCMS , and a v3 will be released soon, that fits exactly your needs : powering the backoffice tool directly in your Next.js app. Keep in mind, if you're going full serverless (with Vercel for example) that you will still need to have a server for your disk storage and your database to run, or you will need to use also serverless solutions for theses parts of your architecture.