lwsjs / local-web-server

A lean, modular web server for rapid full-stack development.
MIT License
1.21k stars 85 forks source link

Proxy fails when sending a POST request with data #30

Closed mgalante closed 8 years ago

mgalante commented 8 years ago

When sending a post body, the proxy doesnt work.

for example:

$.ajax({ 
type: 'post',
data: {"someKey": "someValue"}
...
})
75lb commented 8 years ago

doesn't work in what way? there is not enough information here.. can you send a reproduction case, or just more detail (your local-web-server config, details of what exactly is failing)

mgalante commented 8 years ago

Ok here is the thing. I create to VM in digital ocean in one i create a post.php file its just

<?php var_dump($_POST)

in the other one i started local-web-server with a rule to forward all the traffic to the other server. If i just make a post o get to post.php it works, but if i send something in the post content fails I send the console output.

root@ubuntu-512mb-nyc3-01:~# ws --config
{
  "port": 80,
  "directory": "/root",
  "forbid": [],
  "rewrite": [
    {
      "from": "/*",
      "to": "http://104.131.40.69/$1"
    }
  ]
}
root@ubuntu-512mb-nyc3-01:~# ws
serving at http://ubuntu-512mb-nyc3-01:80, http://127.0.0.1:80, http://159.203.74.157:80, http://10.17.0.7:80
/usr/lib/node_modules/local-web-server/node_modules/koa/lib/context.js:91
    throw createError.apply(null, arguments);
    ^

InternalServerError: [PROXY] socket hang up: http://104.131.40.69/post.php
    at Object.throw (/usr/lib/node_modules/local-web-server/node_modules/koa/lib/context.js:91:23)
    at ProxyServer.<anonymous> (/usr/lib/node_modules/local-web-server/lib/middleware.js:48:17)
    at ProxyServer.emit (/usr/lib/node_modules/local-web-server/node_modules/eventemitter3/index.js:117:27)
    at ClientRequest.proxyError (/usr/lib/node_modules/local-web-server/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js:141:16)
    at emitOne (events.js:95:20)
    at ClientRequest.emit (events.js:182:7)
    at Socket.socketCloseListener (_http_client.js:238:9)
    at emitOne (events.js:95:20)
    at Socket.emit (events.js:182:7)
    at TCP._onclose (net.js:471:12)

I ll leave the LAMP server UP so you can try it: http://104.131.40.69/post.php It will be really usefull for me if you can fix this.

Thanks for your work and sorry for my pour description of the problem before. I just was in a hurry in my daytime job.

75lb commented 8 years ago

You have this rule

"rewrite": [
    {
      "from": "/*",
      "to": "http://104.131.40.69/$1"
    }
  ]

so a local url of /yeah will proxy to http://104.131.40.69/yeah.. what is the full local url you are sending the POST request to?

75lb commented 8 years ago

i set up a local web server with this config

{
  "port": 8000,
  "rewrite": [
    {
      "from": "/*",
      "to": "http://104.131.40.69/$1"
    }
  ]
}

if i run this command, it seems to work:

$ curl -i http://localhost:8000/post.php
HTTP/1.1 200 OK
date: Fri, 19 Feb 2016 10:50:36 GMT
server: Apache/2.4.7 (Ubuntu)
x-powered-by: PHP/5.5.9-1ubuntu4.14
content-length: 13
connection: close
content-type: text/html

array(0) {
}
75lb commented 8 years ago

however, this command hangs:

$ curl -i http://localhost:8000/lloyd/post.php -d '{"someKey": "someValue"}'

will look into it..

75lb commented 8 years ago

are you sure the issue is not server side? your PHP script is hanging, do you understand why?

mgalante commented 8 years ago

Its not my php. If you execute the curl directly will work. And i tried it also with a java servlet with the same result.

It happens with any post request with data.

75lb commented 8 years ago

isolated, confirmed, fixed and released in v1.1.1.. thanks for the report, please tell me if you have any more issues :+1: