Introduction to the

Build a MOCK server! Support for JSON data or Mockjs methods.

Technology stack

  • react
  • ant design Pro
  • egg.js
  • mysql

The front-end and back-end projects belong to different projects. The user name is admin and the password is 123456

// Mock /client front-end engineering
// mock/service back-end project
Copy the code

If it is helpful, you can click “Star” in the upper right corner to support it. Thank you! ^_^

Screenshots of some functions

Add the project

Project directory Refers to the level of the interface directory (for example: HTTP: / / http://localhost:7001/mock/getData/a/mock) in the

Configuring the Project Interface

The interface connection Refers to the directory after connection (for example: http://localhost:7001/mock/getData/a/getData/a) of the support JSON data types, and mockjs data types, pay attention to use double quotation marks;



The test interface

Because the mock service is listened for in the egg ^/ API route, the final access to the mock request connection is prefixed with/API. (http://localhost:7001/api/mock/getData/a).


Run the project

Different ports at the front and back ends are used to resolve cross-domain problems. If devServer is started in the front-end engineering, the back-end engineering must be started first

  • Git clone github.com/lenolee16/m…
  • cd mock

Run the back-end project

  • Ensure that mysql is installed locally and global variables are configured
  • Mysql -u root -p And enter the database password
  • create database mock; Creating a mock database
  • use mock; Switching databases
  • The absolute path to source mock. SQL; For example: source {current directory}/db/mock. SQL;
  • Configure egg.js to connect to database information
/ / to the service/config/config. Local, js, configure your database information
config.sequelize = {
    dialect: 'mysql'.host: '127.0.0.1'.port: 3306.database: 'mock'.username: ' '.password: ' '.operatorsAliases: false
};
Copy the code
  • In the /service file
  • npm install
  • npm run dev

Running front-end projects

  • cd client
  • npm install
  • npm start

If it is helpful, you can click “Star” in the upper right corner to support it. Thank you! ^_^