【问题标题】:NodeJS APN module cannot find certificate file on UbuntuNodeJS APN 模块在 Ubuntu 上找不到证书文件
【发布时间】:2012-06-09 18:17:35
【问题描述】:

我正在使用 apn 模块 (https://github.com/argon/node-apn) 从 NodeJS 向 iPhone 发送推送通知。

我的代码在我的开发机器 (Mac OSX) 上运行良好,并且通过 Apple 沙盒网关 (gateway.sandbox.push.apple.com) 成功推送通知,但是当我将它移动到登台服务器(正在运行Ubuntu)推送通知失败并显示以下消息:

 Error: ENOENT, no such file or directory 'apns-dev-cert.pem'

我正在这样设置 NodeJS apn 对象:

var options = {
    cert: "apns-dev-cert.pem",          
    key:  "apns-key.pem",               
    passphrase: null,   
    gateway: "gateway.sandbox.push.apple.com",              
    port: 2195,                         
    enhanced: true,                     
    errorCallback: undefined,                       
    cacheLength: 5                                  
};

在我的开发 Mac OSX 机器上,证书安装在钥匙串中。根据我对 Ubuntu 的有限理解,相当于将证书文件复制到 /etc/ssl/certs。我尝试这样做,并在我的 NodeJS 代码中将路径更改为“/etc/ssl/certs/apn-dev-cert.pem”,但出现了相同的错误消息。

有什么想法吗?

【问题讨论】:

  • 把你的pem文件保存在你保存上述源文件的地方试试!!!

标签: node.js ubuntu ssl apple-push-notifications


【解决方案1】:

我在这个问题上苦苦挣扎,直到我意识到我不明白fs 模块是如何读取文件的。显然,它从您启动节点进程的目录中读取它们。因此,.pem 文件的路径应该与您执行该操作的位置相关。

你可能也想check out__dirname,也可能是make it easier to specify your paths

【讨论】:

    【解决方案2】:

    你尝试如下设置:

    var options = {
        //cert: "apns-dev-cert.pem",          
        //key:  "apns-key.pem",               
        pfx: '<path>/apns-key.pem',    
        passphrase: null,   
        gateway: "gateway.sandbox.push.apple.com",              
        port: 2195,                         
        enhanced: true,                     
        errorCallback: undefined,                       
        cacheLength: 5                                  
    };
    

    【讨论】:

      猜你喜欢
      • 2011-08-30
      • 1970-01-01
      • 2020-06-14
      • 1970-01-01
      • 2013-02-19
      • 2014-07-21
      • 2017-12-16
      • 2014-01-29
      • 1970-01-01
      相关资源
      最近更新 更多