We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No description provided.
The text was updated successfully, but these errors were encountered:
使用支持json和js文件的简单mock可以满足我们项目的大部分场景需求,实现不超过100行。可以考虑先简单加一个
if (fs.existsSync(filePath)) { // read file from the mock directory const mockData = fs.readFileSync(filePath).toString('utf-8'); res.end(mockData); } else if (fs.existsSync(jsFilePath)) { delete require.cache[jsFilePath]; const result = require(jsFilePath); // searchParams to json const jsonParams = JSON.parse(body || '{}'); reqUrl.searchParams.forEach((value, name) => { jsonParams[name] = value; }); if (result && typeof result === 'function') { res.end(JSON.stringify(result(jsonParams))); } } else { console.log(`file ${filePath} not found`); res.end(`{"ret": "0","msg": "file ${filePath} not found"}`); } });
就是url到文件的路径映射。json直接就是response,js支持模板接口返回数据。
Sorry, something went wrong.
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: