1. What is Strapi?
A set of free CMS system, using API Driven, that is, when consuming STRAPI, strAPI resources can be called through the API provided by StrAPI.
1.1 Advantages of Strapi
- Support multiple databases (SQLite, MongoDB, MySQL, Postgres)
- Api Driven (Isolation can be established between the consumer side and Strapi)
- Authentication&Authorization (based on API Driven, convenient for authority management)
- Permanent free
1.2 Deficiencies of Strapi
- At this stage, there is no complete Migrate solution and data needs to be manually dumped
In general, StrAPI does a good job of meeting our needs for lightweight or microservices.
2. Build strAPI using Docker-compose
2.1 installation docker – compose
This article uses Ubuntu as the target machine, if you use MAC or Windows friends, you can search for yourself, in fact, very easy.
Can follow this article to install the docker – compose. Docs.docker.com/compose/ins…
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
#verify docker-compose installed
docker-compose --version
Copy the code
2.2 write a docker – compose. Yml
The official documentation for Strapi already provides instructions on how to write docker-compose.
Strapi. IO/documentati…
The following yML file uses two docker-images, one is the image of Strapi, the other is a lazy mongo database. Strapi Container data is stored in the app folder of the current folder, and MongoContainer data is stored in the data folder of the current folder. Keep these two folders in mind, and we’ll use them for data migration in a future article.
version: '3'
services:
strapi:
image: strapi/strapi
environment:
DATABASE_CLIENT: mongo
DATABASE_NAME: strapi
DATABASE_HOST: mongo
DATABASE_PORT: 27017
DATABASE_USERNAME: strapi
DATABASE_PASSWORD: strapi
volumes:
- ./app:/srv/app
ports:
- '1337:1337'
depends_on:
- mongo
mongo:
image: mongo
environment:
MONGO_INITDB_DATABASE: strapi
MONGO_INITDB_ROOT_USERNAME: strapi
MONGO_INITDB_ROOT_PASSWORD: strapi
volumes:
- ./data:/data/db
Copy the code
2.3 run the docker – compose
docker-compose down
docker-compose up -d
Copy the code
2.4 Viewing Processes
docker ps # Check all alive processes
docker ps -a # Check all processes, including stopped
Copy the code
3. Add the content-type
3.1 Run docker-compose as described above
After using Docker-compose, you can view the Docker Container that is already running. The red boxes are the two containers described in docker-comemage. yml above. The first line is the StrAPI consumer, which we’ll cover later.
3.2 Open the StrAPI website
After strAPI container is started for the first time, StrAPI installs front-end applications. The time required varies according to network conditions. A little trick, if you can’t wait, you can install it manually.
The method is as follows:
docker exec -it 4a7e94 # 4a7e94 is the strapi-container ID obtained above
npm install
Copy the code
When you open the website for the first time, you will be asked to create a user name and password of super admin account. Remember this password, otherwise you will not be able to log in later!
3.3 The Admin page is displayed
Once super-admin is created, the page will look like the one above. Click the “Open the Administration” button to enter the Admin page.
3.4 clickContent-Types Builder
- Click on the “the content-type Builder”
- Click “Create New Collection Type”
- The Follow wizard creates your Collection Content Type. As the name suggests, Collection Content Type is equivalent to a table in the database, and Single Content Type is equivalent to a singleton
- One thing to note is that Strapi supports table-to-table relationships just like a relational database, and you can define the fields that each table displays in the relationship
- For example, now I have created two Collection Types Entity1 and Entity2
- Entity1 contains the name and username fields
- Entity2 has a name field in it, and now I want each Entity1 to have an Entity2
- You need to select Entity2, click “Add New Field”, and then select Relationship
- If you select Entity1 as the relational item, the first field in Entity1, name, is selected by default
- We can modify the name of Entity1 displayed in the RelationshipField by editing Entity2’s Relationship field (the default is the first field)
name
, let’s demonstrate how to change to the second fieldusername
)- Go to Content-Type Builder, go to Entity2, and click Configure the View.
- Click on Entity1 in Relation Fields
- Change entity-title from name to ‘username’ in pop-up window
- Re-create Entity2 to display entity1.username
4. Expose apis
- Click Settings in the sidebar
- Click roles under USERS & PERMISSIONS PLUGINS
- Click on pbulic to configure the API to expose
- Check the API to expose and on the right side StrAPI will show us the FORMAT of the API
- You can use tools like Postman for testing
- You can view the newly added entity in the Entity1 list of Strapi