Code Monkey home page Code Monkey logo

edp-webserver's Introduction

edp-webserver

NPM version edp docs Build Status Dependencies Status

Package for edp webserver.

edp-webserver's People

Contributors

acecode avatar chriswong avatar erik168 avatar firede avatar guoyao avatar jinzhubaofu avatar junmer avatar justineo avatar kekee000 avatar leeight avatar liuxuanzy avatar mkwiser avatar monwf avatar otakustay avatar pengxing avatar yanghuabei avatar

Stargazers

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

edp-webserver's Issues

提供将目录定向到目录的功能

如后端认定的URL是static/xxx.html,对FE来说应该是${DOC_ROOT}/xxx.html,因此最好能这么配:

{
    location: /static\//,
    handler: dir('.')
}

重构lib/resource.js

文件太大了,把各个handler独立出来,另外增加了对edp-core的依赖,日志输出的时候使用edp.log

处理错误日志

现在less等一些编译脚本,如果less文件有语法错误,不会打印出错误信息,很难排查问题

打印出错误日志

location 为字符串时,走 minimatch 的规则匹配

minimatch 的功能:

Supports these glob features:

  • Brace Expansion
  • Extended glob matching
  • "Globstar" ** matching

See:

  • man sh
  • man bash
  • man 3 fnmatch
  • man 5 gitignore

这规则还蛮通用的,包括 .gitignoregrunt 等,就是常见的 /a/**/*.js 形式(匹配所有 a 目录及其子目录下后缀为 js 的文件)。

proxy当远程服务器连不上时会中断

信息如下

Gray's MacBook Pro:cb-web-2 otakustay$ ws
EDP WebServer start, root = [/Users/otakustay/Dev/cb-web-2], listen = [8080] 
[2013/7/2 11:9:11] Forward request localhost:8080/favicon.ico to 10.81.57.15:8080/favicon.ico

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: connect ECONNREFUSED
    at errnoException (net.js:883:11)
    at Object.afterConnect [as oncomplete] (net.js:874:19)

此时远程机网络无法连通,但本地测试也没需要远程机,就因为一个favicon挂了……

proxy资源存在一些问题

首先,当使用proxy资源时,会改写真正发到远端服务器的请求中的Host头:https://github.com/ecomfe/edp-webserver/blob/master/lib/resource.js#L689

这个在实际应用中存在问题,有些后端的跳转(response.redirect)会根据这个Host头给出Location响应头的内容,这会导致302返回的Location头不合预期,因此要去掉这行代码


其次,发现返回时Content-Type头有重复,一个是正常的,一个是undefined

image

同时各header也变成小写的了,这在验证一些HTTP头时非常具有干扰性,应当保持 完全一致

http2下,通过edp-webserver代理会导致crash

Error: Cannot set deprecated header: connection
    at OutgoingResponse.setHeader (/usr/local/lib/node_modules/edp-webserver/node_modules/http2/lib/http.js:367:13)
    at OutgoingResponse.writeHead (/usr/local/lib/node_modules/edp-webserver/node_modules/http2/lib/http.js:716:10)
    at /usr/local/lib/node_modules/edp-webserver/lib/resource.js:52:34
    at Gzip.onEnd (zlib.js:227:5)
    at Gzip.emit (events.js:129:20)
    at _stream_readable.js:908:16
    at process._tickDomainCallback (node.js:381:11)

php模块 子进程参数传递问题

在调用子进程时,handler是执行的php命令,需要解析的php文件参数并没有被子进程使用,效果是只执行不带参数php ,导致php模块不可用~@leeight

var child = require('child_process').spawn(
       handler,
       [],
       { env: env }
);

[handler/php.js]的几个问题

最近在使用webserver调用php时发现几个问题:

opt_forwardPathName的定义是只提供修改pathname的功能,但实际上很可能同时存在修改search的需要。比如将所有php请求都转给index.php处理,这需要修改pathname,同时在search中添加参数pathname=xxx;

希望能将此参数重新定义,可以有两个方向:

  • 不需要返回值,所有修改都直接对context.request直接操作
  • 返回key-value格式数据

比如

{
    pathname: '/index.php',
    search: '?a=1&pathname=/some/where'
}

child.stderr的end事件处理

chunk为空也会触发end事件。

image

node版本是0.10.26, mac OSX 10.92

Content-Length的处理有问题,导致POST请求超时。

if ('content-length' in request.headers) {
     env.CONTENT_LENGTH = request.headers['content-length'];
}

目前的逻辑是在header中有Content-Length就加上,没有就算了。在实际测试中,浏览器可能不发这个。

比如:

$.post(conf.uiRoot + '/trade/fund/buy', $(this).serialize()).then(function (result) {
      console.log(result);
}, function (error) {
      console.log(error);
});

浏览器Chrome 34.0.1847.13, mac OSX 10.92

由于没有Content-Length,导致php-cgi一直等待,直到超时结束。

按照这篇文章的分析,可以把对php-cgi的调用模式直接设定为Transfer-Encoding: Chunked,而不计算Content-Length

mac上测试没有问题 ,windows上未知。

使用es6 generator来做webserver

为紧密跟随 @errorrik **领导人提出的关于“建立前端基础技术产品的任务发布运作方式”的提议,将此任务作为一个技术型的issue放在这, @leeight 你们就不用管这个了,我希望可以有兴趣的同学自觉捡来做,也当练手

具体的,参考koa去- -做完了希望是个更漂亮的webserver

handler中的header出错

edp-webserver-config.js中配置header会出错

{
      location: /^.*$/,
      handler: header({
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Headers': 'X-Requested-With',
             'Access-Control-Allow-Methods': 'GET,POST,OPTIONS'
       })
}

经查,在resource.js中添加header处理函数,错误地使用了mix.js,导致报错。

应当将mix.js作如下修改

// @file mix.js

module.exports = function () {
 // ...
}

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.