【问题标题】:Heroku Foreman Exits on Express.js bodyParser() callHeroku Foreman 退出 Express.js bodyParser() 调用
【发布时间】:2013-12-21 20:00:24
【问题描述】:

运行工头启动时,我看到以下消息

> foreman start
20:38:55 web.1  | started with pid 3896
20:38:55 web.1  | Development
20:38:56 web.1  | connect.multipart() will be removed in connect 3.0
20:38:56 web.1  | exited with code 1
20:38:56 system | sending SIGKILL to all processes

我想知道为什么会这样,因为运行 node server.js 似乎不会终止服务器。

这是导致应用程序以退出代码 1 终止的代码段:

var app = express();
app.configure(function()
{
    // More config things above
    app.use(express.bodyParser());   // This line is causing the issue
    // More config things below
}

以上是使用Express.js 框架的代码。删除上述对 express.bodyParser() 的调用允许服务器运行(通过工头)。问题是,我需要 body 解析器模块来解析传入的 get/posts 请求。

对于这个问题的任何帮助将不胜感激。

【问题讨论】:

    标签: javascript node.js heroku express foreman


    【解决方案1】:

    我不知道为什么在 express 报告弃用警告时工头退出,但您可以消除这种行为,将 app.use(express.bodyParser()); 替换为

    app.use(express.json()); app.use(express.urlencoded());

    connect.multipart() 将在下一版本的 Connect 中从 bodyParser 中删除,这可能就是问题所在。您可以在Connect documenattion 和/或this StackOverflow Q&A 中找到更多信息。

    【讨论】:

    • bodyParser() = json() + urlencoded() + multipart()。如果您不使用文件上传,则无需包含multipart() 中间件。即使您使用文件上传,您也可以使用formidable 或任何其他模块来处理文件上传。
    • @vmx,您是否知道任何将强大的明确用作快速/连接模块的示例(我相信它在 bodyParser 中使用)
    • multipart() 在用作通用中间件时被认为存在安全问题,正如@vmx 指出的那样,最好使用强大的来显式处理文件上传
    猜你喜欢
    • 2015-08-01
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-04
    • 2019-11-09
    • 2013-06-07
    相关资源
    最近更新 更多