【问题标题】:Parse Server (express) Error: Can't set headers after they are sent解析服务器(快速)错误:发送后无法设置标头
【发布时间】:2016-07-25 10:06:41
【问题描述】:

我在 NodeChef 上运行的 Parse Server 上使用以下功能:

var sendMail = function(sendMailData) {
    return Parse.Cloud.httpRequest({
        method: 'POST',
        url: 'https://api.sparkpost.com/api/v1/transmissions',
        body: {
            content: {
                from: 'noreply@domain.com',
                subject: sendMailData.subject,
                template_id: sendMailData.templateId,
            },
            substitution_data: sendMailData.substitution_data,
            recipients: sendMailData.recipients
        },
        headers: {
            'Authorization': 'AUTHKEY',
            'Content-Type': 'application/json'
        }
    });
}

sendMail(defaultSendMailData).then(function(okresp) {
    var attemptedSend = false;
    if (request.user.get('config')) {
        var userConfig = request.user.get('config')
        if (userConfig.copyPrescription === true) {
            attemptedSend = true;
            sendMail(defaultSendMailData).then(function(okresp) {
                var attemptedSend = false;
                if (request.user.get('config')) {
                    var userConfig = request.user.get('config')
                    if (userConfig.copyPrescription === true) {
                        attemptedSend = true;
                        sendMail(copyPrescriptionSendMailData).then(function(okresp) {
                            console.log('Woohoo! You just sent your first mailing 1!');
                            response.success("Great! Your program has been sent!");
                        }, function(errresp) {
                            console.log('Whoops! Something went wrong 1');
                            console.log(errresp);
                            response.error(errresp);
                        });
                    }
                };
                console.log('Woohoo! You just sent your first mailing 2!');
                if (!attemptedSend) {
                    response.success("Great! Your program has been sent!");
                }
            }, function(errresp) {
                console.log('Whoops! Something went wrong 2');
                console.log(errresp);
                response.error(errresp);
            });
        });
    }
});

并得到以下错误:

at Immediate.<anonymous> (/bundle/node_modules/express/lib/router/index.js:618:15) 
at Immediate.<anonymous> (/bundle/node_modules/express/lib/application.js:232:9) 
at next (/bundle/node_modules/express/lib/router/index.js:271:10) 
at Function.process_params (/bundle/node_modules/express/lib/router/index.js:330:12) 
at /bundle/node_modules/express/lib/router/index.js:280:7 
at trim_prefix (/bundle/node_modules/express/lib/router/index.js:312:13) 
at Layer.handle [as handle_request] (/bundle/node_modules/express/lib/router/layer.js:95:5) 
at jsonParser (/bundle/node_modules/parse-server/node_modules/body-parser/lib/types/json.js:94:7) 
at next (/bundle/node_modules/express/lib/router/index.js:271:10) 
at Function.process_params (/bundle/node_modules/express/lib/router/index.js:330:12) 
at /bundle/node_modules/express/lib/router/index.js:280:7 
at trim_prefix (/bundle/node_modules/express/lib/router/index.js:312:13) 
at Layer.handle [as handle_request] (/bundle/node_modules/express/lib/router/layer.js:95:5) 
at allowCrossDomain (/bundle/index.js:439:9) 
at ServerResponse.header (/bundle/node_modules/express/lib/response.js:719:10) 
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:344:11) 
Error: Can't set headers after they are sent.

虽然该功能似乎可以工作,但我担心这个错误以及它的来源。我不相信 Parse.com 上是这种情况(我使用的是完全相同的代码)。此错误未显示在我的 Parse.com 日志中。这次(第三次尝试!)对我的 Parse Server 生产部署的任何帮助将不胜感激。

【问题讨论】:

  • 为什么attemptedSend要声明两次?
  • 根据userConfig 的结果,我向用户发送第二封不同内容的电子邮件。
  • 另外,您的缩进是错误的,并且您缺少很多右括号,并且在您的示例使用中响应似乎未定义。
  • 我看到你有一些打印声明。控制台输出看起来如何?
  • [32minfo[39m:运行云函数 sendUserProgramme 与:Woohoo!您刚刚发送了您的第一封邮件 1! 2016-07-25 10:45:51 哇哦!您刚刚发送了您的第一封邮件 2!功能似乎运行良好...之后我收到错误 2016-07-25 10:45:52 ERROR

标签: node.js express parse-platform parse-server


【解决方案1】:

感谢上述所有 cmets 尝试解决此问题。 Node Chef 联系了我,他说:

该错误是由周六的 2.2.17 解析服务器更新引起的。

其他用户注意到并报告了它,我们不得不回滚 更新。

目前,自动更新已关闭,您可以手动更新 随时从服务器设置 > 运行时设置更新服务器 在您确信新版本将与您的应用完美配合之后。

回滚已经成功,我现在没有任何错误。

【讨论】:

    猜你喜欢
    • 2014-12-09
    • 1970-01-01
    • 2018-11-28
    • 1970-01-01
    • 2018-06-08
    • 2018-06-29
    • 2013-12-22
    相关资源
    最近更新 更多