-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
27 lines (25 loc) · 897 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* mock server plugin for uba-server
* Date : 2018-04-25 10:53:13
*/
const serveStatic = require('serve-static');
const chalk = require('chalk');
const path = require('path');
module.exports = (app, mockConfig) => {
for (let item in mockConfig) {
for (let i = 0; i < mockConfig[item].length; i++) {
for (let url in mockConfig[item][i]) {
console.log(chalk.green(`[mock]:${item} [${url}] to ${mockConfig[item][i][url]}`));
app[item.toLowerCase()](url, (req, res) => {
console.log(chalk.green(`[mock]: ${req.method} ${req.ip} client router [${url}]-[${mockConfig[item][i][url]}]`));
res.sendFile(path.resolve(".", mockConfig[item][i][url]), {
headers: {
"Uba-Server-Mock": require("./package.json").version,
"Access-Control-Allow-Origin": "*"
}
});
});
}
}
}
}