YAPI安装二次开发

Mongodb安装

参考:https://blog.csdn.net/baidu_38981831/article/details/86265645

设置yapi数据库

> db.auth('admin','123456') 
1
> use yapi
switched to db yapi
> db.createUser({user:'admin',pwd:'123456',roles:[{role:"dbOwner",db:"yapi"}]})
Successfully added user: {  
        "user" : "admin",
        "roles" : [
                {
                        "role" : "dbOwner",
                        "db" : "yapi"
                }
        ]
}

yapi安装

参考:https://hellosean1025.github.io/yapi/documents/redev.html

其他

高级mock接口支持open token方式请求

位置:/vendors/server/controllers/base.js,方法async init ,54行

变量openApiRouter新增:'/api/plugin/advmock/save'

此时就可以通过设置token的方式调用更改高级Mock中的脚本了,也就是/api/plugin/advmock/save

 let openApiRouter = [
      '/api/open/run_auto_test',
      '/api/open/import_data',
			'/api/interface/add',
			'/api/interface/save',
			'/api/interface/up',
			'/api/interface/get',
			'/api/interface/list',
			'/api/interface/list_menu',
			'/api/interface/add_cat',
      '/api/interface/getCatMenu',
      '/api/interface/list_cat',
      '/api/project/get',
      '/api/plugin/export',
      '/api/project/up',
      '/api/plugin/advmock/save'
    ];

高级Mock脚本支持nodejs require调用

位置:vendors/server/utils/commons.js:295

改动:    vm.run(script, 'vm.js')

exports.sandbox = (sandbox, script) => {
  try {
    const { NodeVM } = require('vm2');
    sandbox = sandbox || {};
    const vm = new NodeVM({
      require: {
        external: true
      },
      sandbox: sandbox,
      timeout: 3000
    })

    vm.run(script, 'vm.js')
    return sandbox
  } catch (err) {
    throw err
  }
};

然后就可以在高级mock脚本中:

var request = require('request');
request('https://www.baidu.com', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body) // 请求成功的处理逻辑
  }
});

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值