Professional Documents
Culture Documents
Frontier123
Posted on Feb 13
To avoid such question and extend flexibility of our company blog for better SEO purpose,
we decide to build it using Nextjs and Strapi, a headless content management system
(CMS) and host that on the xxx.page server.
To do that, you will have to refer to docs first:
Nextjs
Strapi
from basic introduction we can understand what we can do with this suite:
Nextjs provides intelligent default setup for SSR, SSG purpose, along with default
optimization function, the default Rust-based compiler provides 5x times faster than
babel
Strapi provides a built-in UI dashboard that allows user to do everything you want with
content, and since it is a Node project, you can add more configuration to it, like image
compression function, database connection, email channel, etc.
Strapi as backend
In this case, Strapi is the backend where content is stored. We decide to install docker
image of Strapi directly on the server, and if more config needed to be added in code, we
can do it in server directly.
Doing that can actually save lot of trouble, there is no need for writing code in Strapi to
connect to database, since we store files in server directly, like WordPress, and else
functions can all be done directly on its dashboard.
You can choose other headless CMS, well, Jamstack's headless cms section is a good
place to offer those options
after hosting your Strapi project and make couple content types and publish, for example,
articles or posts, or else, you can access to the json data by checking the url
https://dev.to/zhangjt9317/how-to-setup-a-blog-with-headless-cms-strapi-and-nextjs-14fo 2/8
2/14/22, 2:06 PM How to setup a blog with headless CMS (Strapi) and Nextjs - DEV Community
Nextjs is the frontend, and we use static generator to do so, we will use Jenkins to do a
daily trigger everyday 4:00pm to build the entire blog so everything is included in the
build, and thus providing better user interaction since it is fast.
First, lets take a look of hosted Strapi:
https://dev.to/zhangjt9317/how-to-setup-a-blog-with-headless-cms-strapi-and-nextjs-14fo 3/8
2/14/22, 2:06 PM How to setup a blog with headless CMS (Strapi) and Nextjs - DEV Community
after clicking the open administrator and signup and login, you will see:
https://dev.to/zhangjt9317/how-to-setup-a-blog-with-headless-cms-strapi-and-nextjs-14fo 4/8
2/14/22, 2:06 PM How to setup a blog with headless CMS (Strapi) and Nextjs - DEV Community
The blank Strapi project should not have those collection types on the left side, and
you can feel free to build whatever content type you want in Content-Types Builder , feel
free to explore Strapi doc here
Here I will demonstrate how to do the client side:
1. start a Nextjs project by using
npx create-next-app@latest
# or
https://dev.to/zhangjt9317/how-to-setup-a-blog-with-headless-cms-strapi-and-nextjs-14fo 5/8
2/14/22, 2:06 PM How to setup a blog with headless CMS (Strapi) and Nextjs - DEV Community
process.env.NEXT_PUBLIC_STRAPI_API_URL + "/auth/local",
identifier: process.env.STRAPI_IDENTIFIER,
password: process.env.STRAPI_PASSWORD,
);
return data.jwt;
const p = `${process.env.NEXT_PUBLIC_STRAPI_API_URL}${path}`;
return p;
return data.reverse();
https://dev.to/zhangjt9317/how-to-setup-a-blog-with-headless-cms-strapi-and-nextjs-14fo 6/8
2/14/22, 2:06 PM How to setup a blog with headless CMS (Strapi) and Nextjs - DEV Community
then you can fetch articles using this method along with Nextjs's provided data fetching
methods such as and
getStaticProps or , for
getStaticPaths getServerSideProps
details, check this page
one example of fetching articles would be
// for root path '/', getStaticPaths cannot be used, // only use it in places lik
export async function getStaticPaths() {
return {
params: {
slug: article.slug,
},
})),
fallback: "blocking",
};
// this is required
return {
revalidate: 10,
};
the default gives only limited number of entries that can be fetched, you can add
/articles?_limit=-1 to replace to access unlimited number of entries.
/articles
Right now we have a blog that requires building every time, but if we update like 50 blogs
per day, or like Twitter it may have up to 500M new tweets per day, you will have to define
skeleton and let articles or tweets to be statically generated now time, if they are not
included in the build. this can be explained later as I am also working on it.
https://dev.to/zhangjt9317/how-to-setup-a-blog-with-headless-cms-strapi-and-nextjs-14fo 7/8
2/14/22, 2:06 PM How to setup a blog with headless CMS (Strapi) and Nextjs - DEV Community
Discussion (0)
Code of Conduct • Report abuse
Frontier123
EDUCATION
University of Washington
WORK
Frontend Dev at Desty.app
JOINED
Oct 6, 2020
https://dev.to/zhangjt9317/how-to-setup-a-blog-with-headless-cms-strapi-and-nextjs-14fo 8/8