简体   繁体   English

在云功能中引用PEM文件

[英]Reference a pem file in a cloud function

I am trying to convert a firebase-queue worker to send push notification to a cloud function. 我正在尝试转换firebase-queue工作程序以将推送通知发送到云功能。 I am using node-apn to send push notification to iOS devices. 我正在使用node-apn将推送通知发送到iOS设备。 It requires setting up a connection which requires me to specify a key.pem file and cert.pem file. 它需要建立一个连接,该连接需要我指定一个key.pem文件和cert.pem文件。 These files are present at the same location where the worker js file is present and works without any problem. 这些文件位于存在工作js文件的相同位置,并且可以正常工作。 I moved over the code to a cloud function but I get this error in the Logs console 我将代码移至云函数,但在日志控制台中收到此错误

{ Error: ENOENT: no such file or directory, open './cert.pem'
    at Error (native)
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: './cert.pem' } 'Unable to send push notification to iOS device. Socket Error'

Below is how the files are specified and the connection is created in the code 以下是在代码中指定文件和创建连接的方式

var connectionOptions = {
  cert:'./cert.pem',
  key:'./key.pem',
  production: true
};

var apnConnection = new apn.Connection(connectionOptions);

I have tried specifying the cert file as ./cert.pem and cert.pem but I get a similar error in both the cases. 我尝试将证书文件指定为./cert.pemcert.pem但在两种情况下都遇到类似的错误。 I guess the problem is that the .pem files are not shipped along with the functions. 我猜问题是.pem文件没有随功能一起提供。

How can I specify such files in a cloud function? 如何在云功能中指定此类文件?

Your path reference isn't quite right for firebase functions. 您的路径参考不适用于firebase函数。

It should be: 它应该是:

var connectionOptions = {
  cert:__dirname + '/cert.pem',
  key:__dirname + '/key.pem',
  production: true
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM