Quick Start

2018-12-08 08:46:56

Install EggBorn Scaffold

$ npm i -g egg-born

Create a project

Create a project named as cabloy-demo,then install all dependencies

$ egg-born cabloy-demo --type=cabloy
$ cd cabloy-demo
$ npm i
  • type:specify the project template: cabloy

Configure MySQL

Egg provides three runtime environments, and EggBorn implements different database access strategies for each runtime environment:

1、unit test environment:Every time service started, the old test database is always deleted and a new test database is created

2、local development environment:Every time service started, the available test database is always looked up, and if not found, a new one is created

3、production environment:The database needs to be created manually and specified in config.prod.js

Through these database access strategies, debugging data can be very convenient in the development stage. For example, the database architecture changes frequently during the development stage, when only one unit test command is needed to take effect. The basic operation is as follows:

# run unit test
$ npm run test:backend
# start local development service
$ npm run dev:backend

Therefore, it is necessary to set up the database connection configuration of the three runtime environments separately

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
      },
    },
  };
  • __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

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
      },
    },
  };
  • 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

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}}',
      },
    },
  };
  • database:The database needs to be created manually

Unit Test

$ npm run test:backend

Cabloy 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

Run

Start backend service

$ npm run dev:backend

Start frontend service

$ npm run dev:front

Enjoy



Comments: