Giter Site home page Giter Site logo

dora-plugin-proxy's Introduction

dora-plugin-proxy

NPM version Build Status Coverage Status NPM downloads

Proxy plugin for dora.


Usage

$ npm i dora dora-plugin-proxy -SD
$ ./node_modules/.bin/dora --plugins proxy

Docs

参数

port

代理服务器端口号。

watchDirs

定义哪些目录下的规则定义可以实时刷新。

watchDelay

目录监听延迟,默认:300 毫秒。

规则定义

在项目目录新增 proxy.config.js 可定制 proxy 规则。

样例:

module.exports = {
  // Forward 到另一个服务器
  'GET https://assets.daily/*': 'https://assets.online/',

  // Forward 到另一个服务器,并指定路径
  'GET https://assets.daily/*': 'https://assets.online/v2/',
  
  // Forward 到另一个服务器,不指定来源服务器
  'GET /assets/*': 'https://assets.online/',
  
  // Forward 到另一个服务器,并指定子路径
  // 请求 /someDir/0.0.50/index.css 会被代理到 https://g.alicdn.com/tb-page/taobao-home, 实际返回 https://g.alicdn.com/tb-page/taobao-home/0.0.50/index.css
  'GET /someDir/(.*)': 'https://g.alicdn.com/tb-page/taobao-home',

  // 本地文件替换
  'GET /local': './local.js',
  
  // Mock 数据返回
  'GET /users': [{name:'sorrycc'}, {name:'pigcan'}],
  'GET /users/1': {name:'jaredleechn'},
  
  // Mock 数据,基于 mockjs
  'GET /users': require('mockjs').mock({
    success: true,
    data: [{name:'@Name'}],
  }),
  
  // 通过自定义函数替换请求
  '/custom-func/:action': function(req, res) {
    // req 和 res 的设计类 express,http://expressjs.com/en/api.html
    //
    // req 能取到:
    //   1. params
    //   2. query
    //   3. body
    // 
    // res 有以下方法:
    //   1. set(object|key, value)
    //   2. type(json|html|text|png|...)
    //   3. status(200|404|304)
    //   4. json(jsonData)
    //   5. jsonp(jsonData[, callbackQueryName])
    //   6. end(string|object)
    //
    // 举例:
    res.json({
      action: req.params.action,
      query: req.query,
    });
  },
};

dora-plugin-proxy's People

Contributors

benjycui avatar greenkeeperio-bot avatar idrinkmorewater avatar saiyagg avatar soda-x avatar sorrycc avatar

Watchers

 avatar  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.