Cannot POST forms using Phusion Passenger with Sails.js/Node.js

帅比萌擦擦* 提交于 2019-12-11 20:59:41

问题


I have a site written with Sails.js that I'm trying to deploy to a server with Passenger on it, and so far I'm not having any luck. While all GET requests work, none of the POST requests seem to actually make it to the application. Everything works perfectly without Passenger.

Test Controller:

module.exports = TestController =

  show: (req, res) ->
    res.view()

  post: (req, res) ->
    res.send(200)

Form:

form(action='/test', method='POST')
    input(type='text', name='test', placeholder='foo')
    input(type='submit', value='Test')

I get a 200: OK response with Postman when not sending parameters, but as soon as I add parameters I get nothing. It either just hangs, or sends me Bad request: GET and HEAD requests may not have bodies error.


回答1:


Phusion Passenger author here. This has got nothing to do with stdin and /dev/null, as @Edy claims. The stdin thing only holds for the app itself, not for the Phusion Passenger process (which is a different process with a different stdin).

Instead, it's possible that this is a Node.js-specific bug in Phusion Passenger. In the next version, 4.0.55 (release goal date: next week Friday), we're introducing pretty major Node.js compatibility improvements which may solve your issue. Up until now Phusion Passenger supports Node.js by emulating its HTTP library. In 4.0.55, we've abandoned that approach in favor of a new, much simpler approach that does not involve emulating or patching anything.

If you're curious whether 4.0.55 fixes your issue, you can get Phusion Passenger from git and check whether the git master version works for you.




回答2:


If you're using Phusion Passenger as standalone and starting it with a system service (like systemd), you'll not able to do POST requests.

The problem is that Phusion Passenger uses STDIN for internal communication but your system service sets its STDIN to /dev/null.

To reproduce this behaviour try starting like this: $ passenger start >/dev/null 2>/dev/null </dev/null.

You could try using passenger as a nginx/apache module.



来源:https://stackoverflow.com/questions/23957952/cannot-post-forms-using-phusion-passenger-with-sails-js-node-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!