Created this app to learn how Strapi and Gatsby work.
Firstly, tried to create the app with yarn create strapi-starter gatsby-blog gatsby-blog
based on this article, but didn't work well so that created an app for each Strapi / Gatsby.
The installation requires the following software to be already installed on your computer:
- Node.js: only LTS versions are supported (v14 and v16). Other versions of Node.js may not be compatible with the latest release of Strapi. The 14.x version is most recommended by Strapi.
- npm (v6 only) or yarn to run the CLI installation scripts.
- Python when using a SQLite database
-
Run
yarn create strapi-app backend --quickstart
to create backend -
If it's successful,
http://localhost:1337/admin/auth/register-admin
will automatically open then register your account
- Go to
Content-Type Builder
and clickCreate new collection type
to createArticle
collection
- Add two
Text
fields for title and content, then addMedia
field for image
-
Click
Save
-
Go to
Content Manager
and clickCreate new entry
-
Input
Article
data and clickSave
then clickPublish
-
Go to
Settings
>USERS & PERMISSIONS PLUGIN
then clickRoles
-
Click
Publish
andArticle
, then checkfind
andfindOne
(if you create single type, check onlyfind
) -
Click
Save
-
Go to
Settings
>GLOBAL SETTINGS
then clickAPI Tokens
-
Click
Create new API Token
and chooseFull access
-
Click
Save
and copy token, then paste it in.env
file at frontend -
Access to
http://localhost:1337/api/articles
to check your API data
-
Run
yarn add @strapi/plugin-graphql
at/backend
-
After installation, you can play around with GraphQL at
http://localhost:1337/graphql
-
Run
gatsby new frontend
to create backend -
Run
yarn add gatsby-source-strapi
at/frontend
-
Run
gatsby develop
, thenhttp://localhost:8000
will automatically open
- Create a
.env
file and add API token
STRAPI_TOKEN=your-api-token
STRAPI_API_URL=http://localhost:1337
- Go to
gatsby-config.js
and add this setting insideplugins
{
resolve: "gatsby-source-strapi",
options: {
apiURL: process.env.STRAPI_API_URL || "http://localhost:1337",
accessToken: process.env.STRAPI_TOKEN,
collectionTypes: [],
singleTypes: [],
}
}
- Add your collection types / single types in
collectionTypes
/singleTypes
collectionTypes: ['article'],
- You may need to re-run
gatsby develop
after 6