Giter Site home page Giter Site logo

dora-plugin-proxy's People

Contributors

benjycui avatar greenkeeperio-bot avatar idrinkmorewater avatar infeng avatar kunsam avatar pigcan avatar saiyagg avatar sorrycc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dora-plugin-proxy's Issues

无法跨域问题

看到源码的rule里面有配置'access-control-allow-origin': '*'
可是访问接口的时候依然提示No 'Access-Control-Allow-Origin' header

proxy: proxy.config.js parse error: ReferenceError: localStorage is not defined

提示这个是少安装什么吗?
"dependencies": {
"antd": "^2.5.0",
"classnames": "^2.2.5",
"dva": "^1.1.0",
"js-cookie": "^2.1.3",
"qs": "^6.2.0",
"react": "^15.1.0",
"react-dom": "^15.1.0",
"recharts": "^0.19.0"
},
"devDependencies": {
"atool-build": "^0.7.6",
"babel-eslint": "^6.0.4",
"babel-plugin-dev-expression": "^0.2.1",
"babel-plugin-dva-hmr": "^0.1.0",
"babel-plugin-import": "^1.0.1",
"babel-plugin-transform-runtime": "^6.9.0",
"babel-runtime": "^6.9.2",
"dora": "^0.4.3",
"dora-plugin-proxy": "^0.8.5",
"dora-plugin-webpack": "^0.8.1",
"dora-plugin-webpack-hmr": "^0.2.1",
"eslint": "^2.13.1",
"eslint-config-airbnb": "^9.0.1",
"eslint-plugin-import": "^1.8.1",
"eslint-plugin-jsx-a11y": "^1.4.2",
"eslint-plugin-react": "^5.1.1",
"glob": "^7.0.5",
"mockjs": "^1.0.1-beta3",
"redbox-react": "^1.2.10",
"robe-ajax": "^1.0.0",
"watchjs": "^0.0.0"
}

清理输出日志

现在的日志是:

> dora -p 8001 --plugins atool-build,proxy,hmr

           dora: listened on 8001
          proxy: load rule with proxy.config.js
Anyproxy rule: dora-plugin-proxy
Anyproxy rules initialize finished, have fun!
web interface is disabled
GUI interface started at : http://192.168.2.33:8002/
Http proxy started at 192.168.2.33:8989

received request to : localhost:8989/api/1.js
==>use local rules
received request to : localhost:8989/favicon.ico
==>will forward to real server by proxy

期望的日志:

> dora -p 8001 --plugins atool-build,proxy,hmr

          proxy: load rule from proxy.config.js
          proxy: listened on 8989
          proxy: respond localhost:8989/api/1.js with local file
  • 开启 proxy 时禁用 dora: listened on 8001 提醒
  • 不处理 forward 到 real server 的日志

多文件组织貌似不支持

var comments = require('./mocks/comment');
module.exports = Object.assign({} , comments, {
   'GET /xxx': {}
})

0.6.1版本, 不支持多 mock 文件
proxy: proxy.config.js parse error

怎么改端口

dora -p 8888 --plugins proxy

改完了 端口还是 8989 要怎么写才会改端口

通配转发请求

在做前端开发时,前端的ajax请求通常不能直接访问后台接口,这个时候我们需要做一个反向代理,例如在apache中我们通常这样配置:
ProxyPass /live http://test.live:8080/live
ProxyPassReverse /live http://test.live:8080/live
这样就将所有url包含live的请求转发到 http://test.live:8080/live,那么在这里如何配置呢,能不能类似这样
'POST /live/': ' http://test.live:8080/live/',
'GET /live/': ' http://test.live:8080/live/',
但是这样实际上是不行的,需要对每个请求单独配置
'POST /live/login.do': ' http://test.live:8080/live/login.do'

建议错误提示更加明确

比如:https://github.com/dora-js/dora-plugin-proxy/blob/master/src/getProxyConfig.js#L37

这个地方,直接catch了,导致错误提示不完善,造成的问题就是:

proxy.config.js 里面必须使用'use strict' 才能使用 require的部分库,因为:

Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

建议将这段改成:

      try {
        cache = require(proxyFile);
      } catch (e) {
        log.error(`${configPath} parse error : ${e}`);
      }

怎么设置header

XMLHttpRequest cannot load http://localhost:8989/a.do. Request header field tokenId is not allowed by Access-Control-Allow-Headers in preflight response

我的项目http全局设置这都会传tokenid的header 但是调用dora的api 就报错,因为你们没有配置header
就是想问下 你们怎么配置header

can't install this plugin via npm due to timeout

always getting 504 error:

npm info retry fetch attempt 1 at 18:07:16
npm info attempt registry request try #1 at 18:07:16
npm http fetch GET https://registry.npmjs.org/dora-plugin-proxy/-/dora-plugin-proxy-0.5.3.tgz
npm http fetch 504 https://registry.npmjs.org/dora-plugin-proxy/-/dora-plugin-proxy-0.5.3.tgz
npm info retry will retry, error on last attempt: Error: server error 504
npm info attempt registry request try #2 at 18:08:16
npm http fetch GET https://registry.npmjs.org/dora-plugin-proxy/-/dora-plugin-proxy-0.5.3.tgz

everything other from npm.js installs normally without any 504 errors

Error: spawn D:\code\listen\_WebApp\node_modules\dora-anyproxy\cert\gen-rootCA.cmd ENOENT

D:\code\listen_WebApp>dora --plugins proxy

failed to create cert dir ,please create one by yourself - \Users\Junz.anyproxy_certs\

this error will not block main thread unless you use https-related features in anyproxy

      proxy: load rule from proxy.config.js

(node:8332) DeprecationWarning: 'GLOBAL' is deprecated, use 'global'
temp certs cleared
events.js:160
throw er; // Unhandled 'error' event
^

Error: spawn D:\code\listen_WebApp\node_modules\dora-anyproxy\cert\gen-rootCA.cmd ENOENT
at exports._errnoException (util.js:1007:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:182:32)
at onErrorNT (internal/child_process.js:348:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
at Module.runMain (module.js:577:11)
at run (node.js:348:7)
at startup (node.js:140:9)
at node.js:463:3

完全搞不懂什么原因。。。node版本6.2.2 检查过openssl 命令可用

mock 如何处理中文?

module.exports = {
  'GET /api': function(req, res){
    res.json(
      { "title": "中文" }
    );
    res.set("Content-Type", "application/json; charset=UTF-8");
  },
  "GET /api2": { "title": "中文2" },
};

0.3.0

  • 支持 proxy.config.js,可处理为本地、远程和函数的方式,配置方式
  • 支持 mock.js,#2
  • 支持本地缓存
  • 补充文档

优化对 GraphQL mock 的支持

如果项目使用了 GraphQL,那么所有的请求都是往同一个 url post GraphQL 语句,现在的话只能通过自定义函数替换请求,感觉都要把整个服务器给实现出来了 😂

斜杠由/变成了\

有大神解答下么,我们在开发基于阿里的ant-design时候,用了里面的代理插件 http://ant-tool.github.io/dora.html#proxyconfigjs 然后我们配置好后,跟踪了一下,我们前端项目(windows机器)上启动了代理,转发到另外一台windows上的tomcat7服务器,然后路径由/变成了\,导致请求失败

problem with cookies

I see at Chrome Developer set-cookie in header, but it never set. I suppose problem is with host or some CROS problems.

my proxy config is quite simple:

module.exports = {
 '/api/syncapi/(.*)': 'http://luxms-web.local/;/syncapi/1.5',
};

that's request headers:

Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8,ru;q=0.6
Connection:keep-alive
Content-Length:48
content-type:application/x-www-form-urlencoded
Host:localhost:8989
Origin:http://localhost:8001
Referer:http://localhost:8001/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36

and that's response headers:

access-control-allow-origin:*
connection:keep-alive
content-type:application/json; charset=utf-8
date:Thu, 09 Jun 2016 10:19:00 GMT
elapsed-time:0.053905010223389
server:nginx/1.8.0
set-cookie:BI-User-Session=48f3c32a-1453-445d-be0c-7ac89cbb566d; expires=Fri, 10 Jun 2016 10:19:38 GMT; path=/;
Transfer-Encoding:chunked
x-nginx-lua-version:10003

can you help me with setting up proxy to process cookies?

proxy.config.js 文件支持路径传入

场景

联调和本地开发需要不同的 proxy 机制,比如本地走 mock,联调时 forward 到另一个接口。

实现

proxy 支持 config 参数,可指定 proxy.config.js 的路径。

使用

"scripts": {
  "dev": "dora --plugins proxy",
  "dev-test": "dora --plugins proxy?config=proxy.config.test.js"
}

代理请求远程服务器Restful API的疑问

@sorrycc 你好!
我用 dva-cli 搭建了一个工程,之前我都是自己 mock 数据的:

'GET /v1/security/Accounts/Self/'  (req, res) {
    setTimeout(() => {
      res.json({
        success: true,
        userInfo: {
          nickname: 'banana',
          age: 25
        }
      });
    }, 500);
  }

现在我希望直接调用远程服务器的API,于是我按照文档配置好了Chrome的代理规则,同时把上面这段代码修改成了(并重新 npm start):

'GET /v1/security/Accounts/Self/' : HOST + '/v1/security/Accounts/Self/',

HOST = 'http://win2012r2.eastasia.cloudapp.azure.com'

这样修改以后,当我调用 /v1/security/Accounts/Self/ 这个接口的时候,控制台有输出下面的内容:

proxy: GET http://win2012r2.eastasia.cloudapp.azure.com/v1/security/Accounts/Self matches GET /v1/security/Accounts/Self/, forward to http://win2012r2.eastasia.cloudapp.azure.com/v1/security/Accounts/Self/

看上去规则应该是生效了
但是实际上并没有请求远程服务器的API,而是本地的,所以 Chrome 下返回了404:
image

所以,请问我到底在哪个环节出了错误?应该如何修改呢?

mock 支持

基于 proxy.config.js,扩展类型为 plainObject 的情况,支持 Mock.js

使用方式如下:

var movie = {
  'id|+1': 1,
  'name': '@Name',
};

module.exports = {
  'GET /movies': {data|5: [movie], success: true},
  'GET /movie/:id': {data: movie, success: true},
}

请求 /movies,返回:

{
    "success": true,
    "data": [
        {
            "id": 3,
            "name": "Gary Wilson"
        },
        {
            "id": 2,
            "name": "Lisa Thomas"
        },
        {
            "id": 2,
            "name": "Ronald Lewis"
        },
        {
            "id": 3,
            "name": "Jason Robinson"
        },
        {
            "id": 5,
            "name": "Karen Lopez"
        }
    ]
}

请求 /movies/3,返回:

{
    "success": true,
    "data": {
        "id": 3,
        "name": "Melissa Moore"
    }
}

Is res providing a subset of Express' API as mentioned?

Hello,

While playing with antd-init result and trying to proxy the requests to static assets, the following rule was included in proxy.config.js file:

  '/assets/*': function(req, res) {

    var options = {
      root: __dirname,
      dotfiles: 'deny',
      headers: {
        'x-timestamp': Date.now(),
        'x-sent': true
      }
    };
    var fileName = req.params[0];
    res.sendFile(fileName, options, function (err) {
      if (err) {
        console.log(err);
        res.status(err.status).end();
      }
      else {
        console.log('Sent:', fileName);
      }
    });
  },

The README includes an example of using custom functions which refers to Express API.
The custom function listed above is using res.sendFile() method. However, a request to
/assets/images/favicon.png crashes the node engine with the following error:

> npm start

> @ start /files/dev/react/ant-demo
> dora -p 8001 --plugins "webpack,hmr,proxy,livereload?enableJs=false&injectHost=127.0.0.1,browser-history?index=/src/entries/index.html"

          proxy: load rule from proxy.config.js
          proxy: listened on 8989
     livereload: listening on 35729
📦  538/538 build modules
webpack: bundle build is now finished.

          proxy: GET /assets/images/favicon.png matches /assets/*, respond with custom function
Caught exception: TypeError: res.sendFile is not a function
    at module.exports./assets/* (/files/dev/react/ant-demo/proxy.config.js:46:9)
    at /files/dev/react/ant-demo/node_modules/dora-plugin-proxy/lib/rule.js:52:11
    at batchMatch (/files/dev/react/ant-demo/node_modules/dora-plugin-proxy/lib/rule.js:174:22)
    at Object.dealLocalResponse (/files/dev/react/ant-demo/node_modules/dora-plugin-proxy/lib/rule.js:37:14)
    at dealWithLocalResponse (/files/dev/react/ant-demo/node_modules/dora-anyproxy/lib/requestHandler.js:94:18)
    at routeReq (/files/dev/react/ant-demo/node_modules/dora-anyproxy/lib/requestHandler.js:86:13)
    at /files/dev/react/ant-demo/node_modules/dora-anyproxy/node_modules/async/lib/async.js:607:21
    at /files/dev/react/ant-demo/node_modules/dora-anyproxy/node_modules/async/lib/async.js:246:17
    at iterate (/files/dev/react/ant-demo/node_modules/dora-anyproxy/node_modules/async/lib/async.js:146:13)
    at /files/dev/react/ant-demo/node_modules/dora-anyproxy/node_modules/async/lib/async.js:157:25
AnyProxy is about to exit with code: 0
> 

Only the following methods are provided for 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)

If yes, what option should I have for the purpose of serving static files directly from such setup, without proxy-ing to other http endpoints, such as an Express instance specifically made for this?

Thanks.

二进制文件支持

utils.js中的normalizeData为什么不支持二进制的数据呢?res.json 已经有针对json数据的处理了,这里可以考虑支持二进制的数据否。

end: function end(data) {
      callback(_status, headers, normalizeData(data));
      return this;
    }

  function normalizeData(data) {
    switch (typeof data === 'undefined' ? 'undefined' : _typeof(data)) {
      case 'string':
        return data;
      default:
        return JSON.stringify(data);
    }
  }
`

 '/custom-func/:action': function(req, res) {
res.type(path);
fs.readFile(path, function (err, data) {
        if (err) {
            res.status(404);
            res.end("404");
            return;
        }
        res.type(srcDir + pathName)
        if (S(mime.lookup(path)).startsWith('image/')) {
            res.end(data);
        } else {
            res.end(data.toString());
        }
    });
}

模式匹配转发会丢失目标子路径

模式规则:

'GET /(.*\.do)': 'http://127.0.0.1:8080/BackGround/'
image
tomcat访问日志:
127.0.0.1 - - [03/Nov/2016:22:46:32 +0800] "GET /finance/getInvoiceByAdvance.do HTTP/1.1" 404 1011

普通转发:

'GET /finance/getInvoiceByAdvance.do': 'http://127.0.0.1:8080/BackGround/'
image

tomcat访问日志:
127.0.0.1 - - [03/Nov/2016:22:45:02 +0800] "GET /BackGround/finance/getInvoiceByAdvance.do HTTP/1.1" 200 2059

proxy.config.js配置不工作

配置如下:

module.exports = {                                                            
  'GET /dispatch':'./',                                                       
  'GET /task':'./index.html',                                                 
  'GET /answer':'./index.html',                                               
  'GET /reply':'./index.html',
  'GET /complete':'./index.html'                                              
};

但是请求http://localhost:8001/dispatch,还是404 Not Found
用了react-router,想让访问这些router的时候,依然返回首页。

Request Json数据问题

跨域请求json格式数据的时候出现
Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response
如果是text/html就不会报错,
我现在的配置

'POST /api/portal/user/login': function(req, res) {
    console.dir(req.header);
    res.set("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type, Accept,Content-Range, Content-Disposition, Content-Description,Set-Cookie,, Access-Control-Request-Method, Access-Control-Request-Headers,Authorization,Authentication");
    res.set("Access-Control-Allow-Methods","GET,POST,PUT,DELETE,PATCH,HEAD,OPTIONS");
    //res.set("Access-Control-Allow-Credentials", "true");
    res.set("Access-Control-Expose-Headers","Set-Cookie,Authorization,Authentication");
    setTimeout(function() {
      res.json({
        success: true,
        entity: [
          {
            id: 1,
            text: 'Learn antd',
            isComplete: true,
          },
          {
            id: 2,
            text: 'Learn ant-tool',
          },
          {
            id: 3,
            text: 'Learn dora',
          }
        ],
      message:'',
      type:'0',
      errorType:'0',
      errorcode:''
      });
    }, 500);
  }.

HTTPS下,Auto Switch + 模式匹配会挂掉

SwitchOmega里,https不能配置url通配符,只能配置域名通配符。
如果我想转发部分目录的请求,剩下一部分送到真实的服务器,就做不到。

比如我配置了:
'/g/h5-lib/nebulamng-fe/0.0.1/(.*)': 'http://localhost:8001/'

在switchOmega里设置 *.test.xxx.net ,这时候请求 a.test.xxx.net/hello.js 就会报错。

按AnyProxy的玩儿法,可以考虑这么做:匹配规则的,返回规则内容,不匹配的,释放到线上真实服务器即可。

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.