Back-end development guide
This document describes how to start the project locally.
We recommend using docker-compose to deploy the required services. A docker-compose.yml file has been provided with the configurations for MySQL, Redis, Elasticsearch, and Kubo IPFS. You can directly use this file to start and manage these services.
Prerequisites
First, make sure that you have the following installed on your machine:
- Node.js (version 18 or later)
- Docker
- Docker Compose
We recommend you have installed nvm in order to set the right node version to run this project
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
Second, you need to apply for the following services:
- IPFS Service, currently support Infura and Fleek, you must choose one of them.
- AlibabaCloud OSS
- SendCloud
- GeeTest CAPTCHA v3
Related resources
Clone this repository and join the folder
git clone https://github.com/Matataki-io/matataki-backend.git
cd matataki-backend
Run with docker-compose
docker compose up -d
- If you are using the Mac OS (M series) operating system.
- You may encounter problems like
no matching manifest for linux/arm64/v8 in the manifest list entries
. To solve this problem, you can consider replacing the image. For example, you could try using a biarms/mysql:5.7-beta-circleci image.
⠿ Network matataki-backend_default Created
⠿ Container mysql_local Started
⠿ Container elasticsearch_local Started
⠿ Container redis_local Started
⠿ Container ipfs_local Started
Environment variable configuration
To modify the project's configuration options, you can follow these steps:
Locate the
config.default.js
file in your projectconfig/
directory. This file contains the default configuration options.Create a copy of
config.default.js
and rename it asconfig.local.js
.In
config.local.js
, you can modify the specific configuration options according to your requirements. The application will prioritize the values defined inconfig.local.js
over the default options specified inconfig.default.js
.Locate the configuration options marked with
@required
. These options are essential for the application to function properly. Make sure to provide the necessary values for these options.Additionally, some configuration options have default values set according to the requirements of Docker Compose. However, it is still recommended to review and adjust these values based on your specific needs.
If you are using Docker Compose's pre-configured service, set the corresponding
host
to the IP address of your local machine (for example,127.0.0.1
) in the configuration environment variable.mysql_local
redis_local
elasticsearch_local
ipfs_local
Start project
Run
yarn
in the project directory to install the necessary dependencies.Initialize the database
yarn run db:init
The following message will be displayed if the database is initialized successfully:
yarn run v1.22.19 $ node ./scripts/database/init.js Connect to mysql_local:3306... Connected to mysql_local:3306 Read SQL file /matataki-backend/database/db-dump.sql... Query SQL file /matataki-backend/database/db-dump.sql... Query SQL file /matataki-backend/database/db-dump.sql done Done in 0.96s.
If you need to execute the database initialization script, set the
mysql
host
inconfig.default
to the IP address of the local machine (for example,127.0.0.1
) when configuring the environment variables. Doing so ensures that the script runs correctly on the local database.Start the development server by running
yarn dev
.Finally, visit http://localhost:7001 to see the website.
Check the status of the services
Exposes 7001
as the default port for the backend service. You can check the status of the backend service by visiting http://localhost:7001 in your browser, it should return a text message like hi, egg, version=1.6.8, undefined
.
Visiting http://localhost:7001/posts/timeRanking can check if you are initializing the database successfully, it should return a JSON message like {"code":0,"message":"成功","data":{"count":0,"list":[]}}
.
Once the backend service is up and running, you are all done with the start.