1. Look at the project structure first

Express initializes the project and configures the mock file in the following directory

2. Mock data for different modules in the mock folder, for example, auditManage.js

Module. exports =[{// interface 1 url: '/audit/list', type: 'get', data: {"code": 200, "data": {"totalRecord": 10, "page": 1, "list": [{ "auditId": 1, "guid": "9ce1270f-8744-463a-9ab2-2456c9d43a9e", "devid": "9ce1270f-8744-463a-9ab2-2456c9d43a9e", "created": "", "type": "", "name": "", "number": "", "model": "", "version": "", "company": "", "opCode": "1", "subject": "", "obejct": "", "kind": "", "level": "", "description": ""," extensions ":" ", "uploadTime" : ""," uploadFlag ":" "}}}}, {/ / interface url: '/ audit/exportExcel, type: 'get' data: {" code ": 200}}, {/ / interface three url: '/ audit/import, type:" post ", data: {" code ": 200, the" message ": ", "data": "}];Copy the code

Mock /index.js imports all modules and exports them

var common = require("./common");
var auditManage = require("./auditManage");
var registManage = require("./registManage");
var systemAccountManage = require("./systemAccountManage");
var unifiedIdentityManage = require("./unifiedIdentityManage");

const apiArr = [
  ...common,
  ...auditManage,
  ...registManage,
  ...systemAccountManage,
  ...unifiedIdentityManage
];

module.exports = apiArr;
Copy the code

4. Loop through the mock file routes/users.js

var express = require('express'); var router = express.Router(); var mockArr = require(".. /mock/index"); /* GET users listing. */ mockArr.forEach(i=>{ router[i.type](i.url,(req,res,next)=>{ res.send(i.data); }); }) module.exports = router;Copy the code

5. Configure the unified request prefix app.js

6. Start the project to send the request