Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
grunt-mock2easy
Advanced tools
通过nodejs的服务实现ajax的跨域访问,使用Curl获取接口,利用mockjs动态生成json接口,模拟多种服务器环境,测试接口并且生成接口文档
click grunt-mock2easy-demo
This plugin requires Grunt ~0.4.5
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-mock2easy --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-mock2easy');
In your project's Gruntfile, add a section named mock2easy
to the data object passed into grunt.initConfig()
.
// 访问本地静态mock数据
grunt.initConfig({
mock2easy: {
test:{
options: {
port:3000,
lazyLoadTime:3000, // 延时加载时间
database:'database',
doc:'doc',
keepAlive:true, // 是否独立运行
ignoreField:['__preventCache', 'secToken'], // 默认忽略的接口入参
interfaceSuffix:'.json' //默认生成为 .json 结尾的接口
}
}
},
});
// 通过Curl访问服务端的接口数据(解决联调困难,所有接口自动进行跨域访问,如果是 windows系统,请先为系统安装 curl 命令)
mock2easy: {
test: {
options: {
port: 3000,
lazyLoadTime:3000,
database: 'database',
keepAlive: false,
ignoreField: ['__preventCache', 'secToken'],
interfaceSuffix:'.json' //默认生成为 .json 结尾的接口
curl: { // curl 这个参数如果配置了,就通过curl访问远程接口,不再访问本地接口
domain: 'http://hello.console.demo.com', // 域名
parameter: { // 每次请求需要带的参数
secToken: 'jimZPPU1MZtLmjFXnxCl22'
},
Cookie: 'kRm9JWrHB9%2B%2Bq84dcf4tLAUfECcVq5NknX2Rs9ic'
}
}
}
}
Type: Number
Default value: 3000
启动的服务的端口号
Type: Number
Default value: 3000
启动接口延时加载,调用接口的延迟时间
Type: String
Default value: mock2easy
接口数据的生成位置
Type: String
Default value: doc
接口文档的生成位置
Type: Boolean
Default value: true
默认为true
,true
时可以独立起一个服务提供接口,false
时可以和别的grunt服务组合成为一个任务串
Type: Object
Default value: false
默认为不写,如果写了的话优先于Curl请求,所有的接口将不再访问本地的mock数据,改为通过Curl访问服务端的接口
Type: Sting
Default value: .json
默认为.json
,产生的接口都是以.json
为后缀的,若你的接口全部都是.action
结尾的话,可以将该属性更改为.action
。
Type: Array
Default value: []
默认为[],可以添加忽略的请求参数,在每次发起请求的时候不去校验这些字段,例如:__preventCache
等字段,可能不是我们想要的校验的参数。
通过 connect 的 middleware 参数将接口转发至 mock2easy 进行处理
修改 Gruntfile.js
中 connect的配置
// demo
connect: {
server: {
options: {
middleware: function(connect) {
return [
require('./database/do') // 引入数据接口生成文件中的do.js脚本
];
},
},
},
},
文档生成默认在 ./doc/
目录下,push 到 git 上可以直接查看
支持所有的mockjs语法,Mockjs语法样例
如果有好的建议和意见请联系我:lhui3it@gmail.com
FAQs
通过nodejs的服务实现ajax的跨域访问,利用mockjs动态生成json接口,模拟各种恶略环境测试系统是否健全,测试接口生成接口文档
The npm package grunt-mock2easy receives a total of 5 weekly downloads. As such, grunt-mock2easy popularity was classified as not popular.
We found that grunt-mock2easy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.