Prerequisites
Name | Version | Link |
---|---|---|
NodeJS | >=10 | https://nodejs.org |
MySQL | >=5.7.27 | https://dev.mysql.com/downloads/mysql/ |
Redis | Latest | https://redis.io |
Any question, see also: FAQ - General
Install Lerna
$ npm i -g lerna
Clone Cabloy Repository
$ mkdir cabloy-lerna
$ cd cabloy-lerna
$ git clone https://github.com/zhennann/cabloy.git
Install Dependencies
$ cd cabloy
$ lerna bootstrap
Config at Front
cp -r src/front/_config src/front/config
Config at Backend
cp -r src/backend/_config src/backend/config
Configure Redis
Cluster
now becomes the first class citizen of CabloyJS
. In other words, the CabloyJS project is ready to be deployed in a clustered environment
The cluster feature of CabloyJS is designed based on Redis
. Therefore, the connection configuration information of Redis
needs to be set. Here, take local development environment
as an example:
src/backend/config/config.local.js
// redis
const __redisConnectionDefault = {
host: '127.0.0.1',
port: 6379,
password: '',
db: 0,
};
const __redisConnectionDefaultCache = Object.assign({}, __redisConnectionDefault, {
keyPrefix: `cache_${appInfo.name}:`,
});
const __redisConnectionDefaultIO = Object.assign({}, __redisConnectionDefault, {
keyPrefix: `io_${appInfo.name}:`,
});
config.redisConnection = {
default: __redisConnectionDefault,
cache: __redisConnectionDefaultCache,
io: __redisConnectionDefaultIO,
};
config.redis = {
clients: {
redlock: config.redisConnection.default,
limiter: config.redisConnection.default,
queue: config.redisConnection.default,
broadcast: config.redisConnection.default,
cache: config.redisConnection.cache,
io: config.redisConnection.io,
},
};
CabloyJS implements multiple features based on
Redis
:limiter, queue, broadcast, cache
. These features access the sameRedis
service by default. When the number of visits increases, separation can be considered
Configure MySQL
EggJS
provides three runtime environments, and CabloyJS
implements different database access strategies
for each runtime environment, see also: Config
Therefore, it is necessary to set up the database connection configuration of the three runtime environments separately
1. unit-test environment
src/backend/config/config.unittest.js
// mysql
config.mysql = {
clients: {
// donnot change the name
__ebdb: {
host: '127.0.0.1',
port: '3306',
user: 'root',
password: '',
database: 'sys', // donnot change the name
hook: {
meta: {
long_query_time: 200,
},
},
},
},
};
Name | Description |
---|---|
__ebdb | the system’s built-in MySQL node name, which is not allowed to change |
database | specified as sys . Every time service started, the old test database is always deleted and a new test database is created |
hook.meta.long_query_time | if the execution time of SQL statement exceeds long_query_time (ms), it will be outputed to the console |
2. local development environment
src/backend/config/config.local.js
// mysql
config.mysql = {
clients: {
// donnot change the name
__ebdb: {
host: '127.0.0.1',
port: '3306',
user: 'root',
password: '',
database: 'sys', // recommended
hook: {
meta: {
long_query_time: 0,
},
},
},
},
};
Name | Description |
---|---|
database | recommendeded as sys . Every time service started, the available test database is always looked up, and if not found, a new one is created |
If specified as the other specific database name, then use this one directly | |
hook.meta.long_query_time | if long_query_time set to 0 ,all of SQL statements will be outputed to the console |
3. production environment
src/backend/config/config.prod.js
// mysql
config.mysql = {
clients: {
// donnot change the name
__ebdb: {
host: '127.0.0.1',
port: '3306',
user: 'root',
password: '',
database: '{{name}}',
hook: {
meta: {
long_query_time: 500,
},
},
},
},
};
Name | Description |
---|---|
database | The database need to be created manually |
hook.meta.long_query_time | if the execution time of SQL statement exceeds long_query_time (ms), it will be outputed to the console |
Unit-Test
$ npm run test:backend
CabloyJS recommends a test-driven
development mode. By test-driven
, you can lock in the results of development, and when there are code changes, you can find problems as soon as possible, so as to solve problems
In addition, the database architecture changes frequently during the development stage, when only one unit test command is needed to take effect, which means that the old test database is always deleted and a new test database is created automatically
Run
Start backend service
$ npm run dev:backend
Start frontend service
$ npm run dev:front
Enjoy
- Website:http://localhost:9192
- User:root
- Password:123456
Docker Compose
There is a docker-compose.yml
configuration file in the root directory of the project. If you have installed the docker compose
environment, you can start all services of CabloyJS with only one command, including Redis, MySQL, Nginx and CabloyJS backend service
$ sudo docker-compose up
Comments: