Coder Social home page Coder Social logo

rap-node-plugin's Introduction

rap-node-plugin

nodejs plugin for RAP

安装

npm install rap-node-plugin --save-dev

使用

var rapnode = require('rap-node-plugin');

global.RAP_FLAG = 1;  // 开启RAP

// 默认是获取85项目下的 `/perf/2014.json` 
rapnode.getRapData(85, '/perf/2014.json', function(err, r) {
    console.log(r);
});

由于已经在rap.alibaba-inc.com中配置了 85 项目,而且配置了/perf/2014.json相关的接口,因此RAP返回的数据结合 Mockjs 以后,数据示例如下:

{ 
    percent: 0.1,
    month_salary: 9,
    perf_total: '3.5B',
    year: 2034,
    perf: 3.5,
    season: '四',
    name: '思竹',
    values: 'B' 
}

API

getRapData([projectId, ]url, [businessFunction,] callback)

  • projectId 可选 项目ID,如果传入了4个参数,则认为第一个参数是项目ID,其他参数顺序往后推。

  • url 必传 请求的Action。此参数可以是object,可实时指定项目ID等信息,例如:

rapnode.getRapData({
    url: '/perf/2014.json',         // action url
    projectId: '85',                // 项目ID,默认请参见config
    port: 80,                       // 端口,默认请参见config
    host: 'rap.alibaba-inc.com',    // 主机,默认请参见config
    rap: false                      // 本次调用关闭rap
}, function() {
    return {a: 1, b: 2}
}, function(err, r) {
    var data = r;
    console.log(data);
});
  • businessFunction 可选 真正获取业务数据的方法,目前暂不支持传参数

  • callback 必传 请求数据后的回调

调用示例

rapnode.getRapData({
    url: '/perf/2014.json', 
    projectId: '85', 
    port: 80,
    host: 'rap.alibaba-inc.com', 
    rap: false
}, function() {
}, function(err, r) {
});
rapnode.getRapData(85, '/perf/2014.json', function() {}, function(err, data))
rapnode.getRapData(85, '/perf/2014.json', function(err, data))
rapnode.getRapData('/perf/2014.json', function(err, data)

config(options)

可以通过 rapnode.config(options) 配置设置,目前的配置项如下:

- `host` rap服务主机
- `port` rap服务端口号(默认是 80)
- `projectId` 项目ID(默认是85)
- `mock` rap服务mockjs请求的路径前缀,默认是 `/mockjs/`
- `wrapper` 返回数据的包装属性名,用于在php或vm中指定根属性名,默认为 `空`,如果设置为`空字符串` 或 `false`,则不包装

配置示例

var rapnode = require('rap-node-plugin');

rapnode.config({
    host: '10.33.12.32',    //启动的服务主机
    port: '7000',           //端口号
    projectId: 67,          //RAP配置的项目ID
    mock: '/mymockjsurl/',  //RAP前缀
    wrapper: ''             //不需要包装
})

说明

  • 默认是从 rap.alibaba-inc.com 获取RAP模拟数据,如果您不是在阿里内网,默认数据是不能使用的

rap-node-plugin's People

Contributors

wangjeaf avatar

Watchers

James Cloos avatar KingxBeta avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.