Node.js and Sendgrid mailer error on res.end - node.js

I'm a bit new to node. I'm using express and the sendgrid api to send an email (collected REST-fully). After sendgrid succeeds or fails, I want to respond with a json object. Here's the sample case:
var SendGrid = require('sendgrid-nodejs').SendGrid;
var sendgrid = new SendGrid(user, key);
app.get('/LGP/:email', function (req, res){
sendgrid.send({
to: req.params.email,
from: 'me#example.com',
subject: 'Hello World',
text: 'This email sent through SendGrid'
}, function(success, message) {
if (!success) {
console.log(message);
} else {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.write(JSON.stringify({ result: 'success' }));
res.end(); //error occurs: "Can't use mutable header APIs after sent."
}
}
);
});
On my local server (using foreman), everything works fine. But when I push it to heroku, it gives me this stack trace:
2013-02-27T22:12:46+00:00 app[web.1]: http.js:543
2013-02-27T22:12:46+00:00 app[web.1]: throw new Error("Can't use mutable header APIs after sent.");
2013-02-27T22:12:46+00:00 app[web.1]: ^
2013-02-27T22:12:46+00:00 app[web.1]: Error: Can't use mutable header APIs after sent.
2013-02-27T22:12:46+00:00 app[web.1]: at ServerResponse.getHeader (http.js:543:11)
2013-02-27T22:12:46+00:00 app[web.1]: at /app/node_modules/express/node_modules/connect/lib/middleware/logger.js:229:26
2013-02-27T22:12:46+00:00 app[web.1]: at ServerResponse.<anonymous> (/app/node_modules/express/node_modules/connect/lib/middleware/logger.js:149:20)
2013-02-27T22:12:46+00:00 app[web.1]: at /app/app.js:60:13
2013-02-27T22:12:46+00:00 app[web.1]: at IncomingMessage.<anonymous> (/app/node_modules/sendgrid/lib/sendgrid.js:74:9)
2013-02-27T22:12:46+00:00 app[web.1]: at IncomingMessage.emit (events.js:81:20)
2013-02-27T22:12:46+00:00 app[web.1]: at HTTPParser.onMessageComplete (http.js:133:23)
2013-02-27T22:12:46+00:00 app[web.1]: at CleartextStream.ondata (http.js:1213:22)
2013-02-27T22:12:46+00:00 app[web.1]: at CleartextStream._push (tls.js:291:27)
2013-02-27T22:12:46+00:00 app[web.1]: at SecurePair._cycle (tls.js:565:20)
2013-02-27T22:12:48+00:00 heroku[web.1]: Process exited with status 1
2013-02-27T22:12:48+00:00 heroku[web.1]: State changed from up to crashed
/app/app.js:60:13 refers to the line with "res.end()". What am I doing wrong?

To maximize your chances of your app behaving the same locally and on heroku, you should make sure you specify specific versions for all modules and avoid using "*" for the main dependencies.
Should also should specify the node version in package.json:
"engines": {
"node": "0.8.20"
}
(use whatever version is appropriate).

Related

Firbase/Heroku/Node JS - Firebase Invalid Credential / failed to parse service account json file / ENAMETOOLONG

I'm using github actions to deploy my first webapp via Heroku.
My code:
const fireBaseAdmin = require('firebase-admin');
if (!fireBaseAdmin)
throw new Error('The FIREBASE_SERVICE_ACCOUNT_CREDS environment variable was not found!');
fireBaseAdmin.initializeApp({
"credential": fireBaseAdmin.credential.cert(JSON.stringify({
"type": process.env.FIREBASE_TYPE,
"project_id": process.env.FIREBASE_PROJECT_ID,
"private_key_id": process.env.FIREBASE_PRIVATE_KEY_ID,
"private_key": process.env.FIREBASE_PRIVATE_KEY.replace(/\\n/g, '\n'),
"client_email": process.env.FIREBASE_CLIENT_EMAIL,
"client_id": process.env.FIREBASE_CLIENT_ID,
"auth_uri": process.env.FIREBASE_AUTH_URI,
"token_uri": process.env.FIREBASE_TOKEN_URI,
"auth_provider_x509_cert_url": process.env.FIREBASE_AUTH_PROVIDER,
"client_x509_cert_url": process.env.FIREBASE_CLIENT
}))
});
module.exports = fireBaseAdmin;
Each of the .env variables are stored in Heroku's Config Vars.
Error log from Heroku (I stripped sensitive tokens/keys):
2021-08-17T11:16:53.818119+00:00 app[web.1]: /app/node_modules/firebase-admin/lib/credential/credential-internal.js:151
2021-08-17T11:16:53.818149+00:00 app[web.1]: throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_CREDENTIAL, 'Failed to parse service account json file: ' + error);
2021-08-17T11:16:53.818150+00:00 app[web.1]: ^
2021-08-17T11:16:53.818150+00:00 app[web.1]:
2021-08-17T11:16:53.818166+00:00 app[web.1]: FirebaseAppError: Failed to parse service account json file: Error: ENAMETOOLONG: name too long, open '{
"type":"service_account",
"project_id":"ec31",
"private_key_id":"2900d",
"private_key":"-----BEGIN PRIVATE KEY-----\nQ=\n-----END\nPRIVATE KEY-----\n",
"client_email":"firebase-adminsdk-.gserviceaccount.com",
"client_id":"10",
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"token_uri":"https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url":"ttps://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url":"https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-o.gserviceaccount.com"
}'
2021-08-17T11:16:53.818167+00:00 app[web.1]: at FirebaseAppError.FirebaseError [as constructor] (/app/node_modules/firebase-admin/lib/utils/error.js:44:28)
2021-08-17T11:16:53.818168+00:00 app[web.1]: at FirebaseAppError.PrefixedFirebaseError [as constructor] (/app/node_modules/firebase-admin/lib/utils/error.js:90:28)
2021-08-17T11:16:53.818168+00:00 app[web.1]: at new FirebaseAppError (/app/node_modules/firebase-admin/lib/utils/error.js:125:28)
2021-08-17T11:16:53.818169+00:00 app[web.1]: at Function.ServiceAccount.fromPath (/app/node_modules/firebase-admin/lib/credential/credential-internal.js:151:19)
2021-08-17T11:16:53.818169+00:00 app[web.1]: at new ServiceAccountCredential (/app/node_modules/firebase-admin/lib/credential/credential-internal.js:67:28)
2021-08-17T11:16:53.818174+00:00 app[web.1]: at Object.exports.cert (/app/node_modules/firebase-admin/lib/credential/credential.js:34:54)
2021-08-17T11:16:53.818174+00:00 app[web.1]: at Object.<anonymous> (/app/firebase/index.js:25:42)
2021-08-17T11:16:53.818175+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1072:14)
2021-08-17T11:16:53.818175+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
2021-08-17T11:16:53.818175+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:937:32)
2021-08-17T11:16:53.818176+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:778:12)
2021-08-17T11:16:53.818176+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:961:19)
2021-08-17T11:16:53.818177+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:92:18)
2021-08-17T11:16:53.818177+00:00 app[web.1]: at Object.<anonymous> (/app/middlewares/auth.js:1:15)
2021-08-17T11:16:53.818177+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1072:14)
2021-08-17T11:16:53.818178+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10) {
2021-08-17T11:16:53.818178+00:00 app[web.1]: errorInfo: {
2021-08-17T11:16:53.818178+00:00 app[web.1]: code: 'app/invalid-credential',
2021-08-17T11:16:53.818190+00:00 app[web.1]: message: `Failed to parse service account json file: Error: ENAMETOOLONG: name too long, open '{
"type":"service_account",
"project_id":"e1",
"private_key_id":"2900",
"private_key":"-----BEGIN PRIVATE KEY-----\\nMIIEMoQ=\\n-----END\\nPRIVATE KEY-----\\n",
"client_email":"firebase-adminsdk-od.gserviceaccount.com",
"client_id":"1",
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"token_uri":"https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url":"ttps://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url":"https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-o.gserviceaccount.com"
}'`
2021-08-17T11:16:53.818190+00:00 app[web.1]: },
2021-08-17T11:16:53.818190+00:00 app[web.1]: codePrefix: 'app'
2021-08-17T11:16:53.818191+00:00 app[web.1]: }
2021-08-17T11:16:53.947406+00:00 heroku[web.1]: Process exited with status 1
2021-08-17T11:16:54.345497+00:00 heroku[web.1]: State changed from starting to crashed
I've been attempted to update my code based on the various posts on Stack Overflow but I'm not having success with solving the error. Here's a short list of the post I've been referencing:
Deploying Firebase App with Service Account to Heroku (environment variables with dotenv)
Authenticating with the Firebase Admin SDK using environment variable
Node.js -Firebase Service Account Private Key won't parse
Firebase: Failed to parse service account: 'project_id' must be set
Any assistance would be greatly appreciated!
The cert() method expects either the path to serviceAccount.json file (string) or a ServiceAccount object. Here you are entering a string so it's expecting that to be the path to serviceAccount.json and not stringified credentials and hence you get the error FirebaseAppError: Failed to parse service account json file. Try this:
fireBaseAdmin.initializeApp({
credential: admin.credential.cert({
type: process.env.FIREBASE_TYPE,
project_id: process.env.FIREBASE_PROJECT_ID,
private_key_id: process.env.FIREBASE_PRIVATE_KEY_ID,
private_key: process.env.FIREBASE_PRIVATE_KEY.replace(/\\n/g, '\n'),
client_email: process.env.FIREBASE_CLIENT_EMAIL,
client_id: process.env.FIREBASE_CLIENT_ID,
auth_uri: process.env.FIREBASE_AUTH_URI,
token_uri: process.env.FIREBASE_TOKEN_URI,
auth_provider_x509_cert_url: process.env.FIREBASE_AUTH_PROVIDER,
client_x509_cert_url: process.env.FIREBASE_CLIENT
}),
databaseURL: `https://${process.env.FIREBASE_PROJECT_ID}.firebaseio.com/`
})

Node: Cannot set headers after they are sent to the client

I did some research on the following error:
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
I understood the idea and what's causing it but I am not sure how to fix it for my controller code:
exports.isServerOnline = (req, res, next) => {
const sock = new net.Socket();
sock.setTimeout(2500);
sock.on('connect', function () {
sock.destroy();
return res.json({
"server": "online"
});
}).on('error', function (e) {
return res.json({
"server": "offline"
});
}).on('timeout', function (e) {
return res.json({
"server": "offline"
});
}).connect(LS_PORT, LS_HOST);
}
I'm using socket to check if a remote host is up or down. Here is my client code (Vue.js):
created() {
this.getServerStatus();
},
methods: {
getServerStatus() {
axios
.get(`${process.env.VUE_APP_BACKEND_URL}/server/status`)
.then(response => {
if (response.data.server === "online") {
// no interesting code here
} else {
// no interesting code here
}
/* eslint-disable no-console */
})
.catch(error => {
console.log(error);
});
}
}
Complete error stack trace:
2020-07-02T07:40:47.743193+00:00 app[web.1]: _http_outgoing.js:518
2020-07-02T07:40:47.743201+00:00 app[web.1]: throw new ERR_HTTP_HEADERS_SENT('set');
2020-07-02T07:40:47.743202+00:00 app[web.1]: ^
2020-07-02T07:40:47.743202+00:00 app[web.1]:
2020-07-02T07:40:47.743204+00:00 app[web.1]: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
2020-07-02T07:40:47.743205+00:00 app[web.1]: at ServerResponse.setHeader (_http_outgoing.js:518:11)
2020-07-02T07:40:47.743206+00:00 app[web.1]: at ServerResponse.header (/app/node_modules/express/lib/response.js:771:10)
2020-07-02T07:40:47.743206+00:00 app[web.1]: at ServerResponse.json (/app/node_modules/express/lib/response.js:264:10)
2020-07-02T07:40:47.743206+00:00 app[web.1]: at Socket.<anonymous> (/app/src/controllers/status.js:15:20)
2020-07-02T07:40:47.743207+00:00 app[web.1]: at Socket.emit (events.js:315:20)
2020-07-02T07:40:47.743207+00:00 app[web.1]: at emitErrorNT (internal/streams/destroy.js:92:8)
2020-07-02T07:40:47.743208+00:00 app[web.1]: at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
2020-07-02T07:40:47.743208+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:84:21) {
2020-07-02T07:40:47.743209+00:00 app[web.1]: code: 'ERR_HTTP_HEADERS_SENT'
2020-07-02T07:40:47.743209+00:00 app[web.1]: }
I would highly appreciate if someone could point me on the right track.
I don't think that approach is correct mate. You are trying to create a socket inside http endpoint, that will not work. Here's gist I found that demonstrates using NodeJS Socket.
https://gist.github.com/tedmiston/5935757
I'll recommend using into something like Socket.io. They have good amount of documentation to get off the ground.

Heroku PDFTK throwing vague EPIPE and EACCES error

I have an app on a heroku hobby web dyno running a fairly basic node api.
We have a series of pdf's that get attached to a pdf generated by puppeteer.
My code works when I run it locally (windows) but it also works when I deploy to a my production heroku instance.
Here's the problematic code:
try{
//If there are pdfs to attach to the end of the file, we do it here.
let fileList = [];
console.log('*');
for (const file of pdfFileNameList) {
fileList.push("./pdfs/" + file.pdf);
}
console.log('**');
//Spawn a child process to run pdftk to merge the pdfs.
let execer = require('child_process').spawn;
let child;
let args = ['-'].concat(fileList).concat(['cat', 'output', '-']);
console.log(args);
console.log('***');
child = execer('pdftk', args, {
encoding: 'binary',
stdio: ['pipe']
});
//Write the file PDF binary data to the child process' stdin.
//It will combine that with the list of pdfs specified in fileList.
console.log('****');
child.stdin.write(data);
console.log('*****');
child.stdin.end();
console.log('******');
let bufferArray = [];
//shove the data from the child process into my bufferArray as it comes in.
child.stdout.on('data', function (pdfdata) {
bufferArray.push(new Buffer(pdfdata, 'binary'));
});
console.log('*******');
//When the process is done, send the concatted pdf to the user.
child.on('close', function () {
res.header('Content-Type', "application/pdf");
res.send(Buffer.concat(bufferArray));
});
console.log('********');
} catch (err) {
console.error(err);
}
And here's the resulting set of errors:
2020-01-16T18:02:37.830775+00:00 app[web.1]: *
2020-01-16T18:02:38.356266+00:00 app[web.1]: **
2020-01-16T18:02:38.358310+00:00 app[web.1]: [ '-', '/app/pdfs/Example.pdf', 'cat', 'output', '-' ]
2020-01-16T18:02:38.358371+00:00 app[web.1]: ***
2020-01-16T18:02:38.373374+00:00 app[web.1]: ****
2020-01-16T18:02:38.375832+00:00 app[web.1]: Error: write EPIPE
2020-01-16T18:02:38.375836+00:00 app[web.1]: at afterWriteDispatched (internal/stream_base_commons.js:149:25)
2020-01-16T18:02:38.375838+00:00 app[web.1]: at writeGeneric (internal/stream_base_commons.js:140:3)
2020-01-16T18:02:38.375843+00:00 app[web.1]: at Socket._writeGeneric (net.js:776:11)
2020-01-16T18:02:38.375845+00:00 app[web.1]: at Socket._write (net.js:788:8)
2020-01-16T18:02:38.375847+00:00 app[web.1]: at doWrite (_stream_writable.js:435:12)
2020-01-16T18:02:38.375849+00:00 app[web.1]: at writeOrBuffer (_stream_writable.js:419:5)
2020-01-16T18:02:38.375851+00:00 app[web.1]: at Socket.Writable.write (_stream_writable.js:309:11)
2020-01-16T18:02:38.375853+00:00 app[web.1]: at Object.returnReport (/app/models/report_functions.js:245:33) {
2020-01-16T18:02:38.375855+00:00 app[web.1]: errno: 'EPIPE',
2020-01-16T18:02:38.375857+00:00 app[web.1]: code: 'EPIPE',
2020-01-16T18:02:38.375859+00:00 app[web.1]: syscall: 'write'
2020-01-16T18:02:38.375861+00:00 app[web.1]: }
2020-01-16T18:02:38.378481+00:00 app[web.1]: events.js:200
2020-01-16T18:02:38.378484+00:00 app[web.1]: throw er; // Unhandled 'error' event
2020-01-16T18:02:38.378486+00:00 app[web.1]: ^
2020-01-16T18:02:38.378488+00:00 app[web.1]:
2020-01-16T18:02:38.378490+00:00 app[web.1]: Error: spawn pdftk EACCES
2020-01-16T18:02:38.378492+00:00 app[web.1]: at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
2020-01-16T18:02:38.378495+00:00 app[web.1]: at onErrorNT (internal/child_process.js:456:16)
2020-01-16T18:02:38.378497+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:81:21)
2020-01-16T18:02:38.378499+00:00 app[web.1]: Emitted 'error' event on ChildProcess instance at:
2020-01-16T18:02:38.378501+00:00 app[web.1]: at Process.ChildProcess._handle.onexit (internal/child_process.js:270:12)
2020-01-16T18:02:38.378503+00:00 app[web.1]: at onErrorNT (internal/child_process.js:456:16)
2020-01-16T18:02:38.378505+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:81:21) {
2020-01-16T18:02:38.378507+00:00 app[web.1]: errno: 'EACCES',
2020-01-16T18:02:38.378509+00:00 app[web.1]: code: 'EACCES',
2020-01-16T18:02:38.378511+00:00 app[web.1]: syscall: 'spawn pdftk',
2020-01-16T18:02:38.378513+00:00 app[web.1]: path: 'pdftk',
2020-01-16T18:02:38.378515+00:00 app[web.1]: spawnargs: [ '-', '/app/pdfs/Example.pdf', 'cat', 'output', '-' ]
2020-01-16T18:02:38.378517+00:00 app[web.1]: }
In case anyone else comes across this error "Error: spawn pdftk ENOENT".
This error is most probably because Heroku can't find 'PdfTK' on your system.
Adding this buildpack to Heroku solved it for me:
'https://github.com/fxtentacle/heroku-pdftk-buildpack.git'
(I added it under the 'heroku/nodejs' buldback)

Kendo UI Angular Upload File to Backend as Node.JS

I am using Kendo Upload Control to upload files to Node.js backend which used GridFS multer.
Angular
<kendo-upload
[saveField]="file"
[withCredentials]="false"
[saveUrl]="uploadUrl"
(autoUpload)="false"
[multiple]="false"
(select)="selectProfilePic($event)"></kendo-upload>
But the node.js API doesn't pick up the request. I am using [saveField]="file" to pass the uploaded file and the node.js below.
var storage = new GridFsStorage({
//url: mongoose.connection.client.s.url,
//options: options,
db: mongoose.connection,
file: (req, file) => {
return new Promise((resolve, reject) => {
myCrypto.randomBytes(16, (err, buf) => {
if (err) {
return reject(err);
}
const filename = buf.toString('hex') + path.extname(file.originalname);
const fileInfo = {
filename: filename,
bucketName: 'uploads'
};
resolve(fileInfo);
});
});
}
});
const upload = multer({ storage });
router.post('/upload', upload.single('file'), fileUpload);
module.exports = router;
function fileUpload(req, res) {
console.log("fileUpload")
try {
res.send({ file: req.file })
}
catch(err){
console.log(err);
res.send(err)
}
}
Logs
2019-07-21T19:34:33.679205+00:00 app[web.1]: File Controller
2019-07-21T19:34:33.680436+00:00 app[web.1]: {}
2019-07-21T19:34:33.983631+00:00 app[web.1]: MulterError: Unexpected
field 2019-07-21T19:34:33.983647+00:00 app[web.1]: at
wrappedFileFilter (/app/node_modules/multer/index.js:40:19)
2019-07-21T19:34:33.983649+00:00 app[web.1]: at Busboy.
(/app/node_modules/multer/lib/make-middleware.js:114:7)
2019-07-21T19:34:33.983650+00:00 app[web.1]: at Busboy.emit
(events.js:198:13) 2019-07-21T19:34:33.983670+00:00 app[web.1]: at
Busboy.emit (/app/node_modules/busboy/lib/main.js:38:33)
2019-07-21T19:34:33.983671+00:00 app[web.1]: at PartStream.
(/app/node_modules/busboy/lib/types/multipart.js:213:13)
2019-07-21T19:34:33.983673+00:00 app[web.1]: at PartStream.emit
(events.js:198:13) 2019-07-21T19:34:33.983674+00:00 app[web.1]: at
HeaderParser. (/app/node_modules/dicer/lib/Dicer.js:51:16)
2019-07-21T19:34:33.983675+00:00 app[web.1]: at HeaderParser.emit
(events.js:198:13) 2019-07-21T19:34:33.983677+00:00 app[web.1]: at
HeaderParser._finish
(/app/node_modules/dicer/lib/HeaderParser.js:68:8)
2019-07-21T19:34:33.983678+00:00 app[web.1]: at SBMH.
(/app/node_modules/dicer/lib/HeaderParser.js:40:12)
2019-07-21T19:34:33.983679+00:00 app[web.1]: at SBMH.emit
(events.js:198:13) 2019-07-21T19:34:33.983680+00:00 app[web.1]: at
SBMH._sbmh_feed (/app/node_modules/streamsearch/lib/sbmh.js:159:14)
2019-07-21T19:34:33.983682+00:00 app[web.1]: at SBMH.push
(/app/node_modules/streamsearch/lib/sbmh.js:56:14)
2019-07-21T19:34:33.983683+00:00 app[web.1]: at HeaderParser.push
(/app/node_modules/dicer/lib/HeaderParser.js:46:19)
2019-07-21T19:34:33.983685+00:00 app[web.1]: at Dicer._oninfo
(/app/node_modules/dicer/lib/Dicer.js:197:25)
2019-07-21T19:34:33.983686+00:00 app[web.1]: at SBMH.
(/app/node_modules/dicer/lib/Dicer.js:127:10)
2019-07-21T19:34:33.989908+00:00 heroku[router]: at=info method=POST
path="/v1/file/upload" host=herokuapp.com
request_id=aa1010df-d244-46bc-9b36-f8e437d5ad2a fwd="80.233.46.84"
dyno=web.1 connect=0ms service=312ms status=500 bytes=286
protocol=https
Is there any chance you had to set the field name to some file variable? So, I believe you expected [saveField]="file" to set field name to 'file' string but instead it searches for some this.filevariable which is undefined so you got field name set to the default 'files' value?
Followed #GProst suggestions and analysed a bit and the below fix worked and I don't know the solution yet.
As per the Kendo UI angular documentation,
Sets the FormData key which contains the files submitted to saveUrl.
The default value is files.
So, I just changed the parameter name from file to files and it worked.
const upload = multer({ storage });
router.post('/upload', upload.single('files'), fileUpload);

ERR! parse-server-push-adapter APNS cannot find vaild connection

Whenever i use the following cloud code to send a push notification on Parse Server 2.2.24
Parse.Push.send({
where: query,
data: {
alert: "You have a new comment on " + rift.get("title")
}
}, { useMasterKey: true }).then(() => {
console.log('Push ok');
}, (e) => {
console.log('Push error', e);
});
I get the following logs with verbose = 1 set on heroku.
2016-11-06T05:08:06.783331+00:00 app[web.1]: verbose: RESPONSE from [POST] /api/1/push: {
2016-11-06T05:08:06.783333+00:00 app[web.1]: "headers": {
2016-11-06T05:08:06.783334+00:00 app[web.1]: "X-Parse-Push-Status-Id": "NbZCxyCOgc"
2016-11-06T05:08:06.783334+00:00 app[web.1]: },
2016-11-06T05:08:06.783335+00:00 app[web.1]: "response": {
2016-11-06T05:08:06.783336+00:00 app[web.1]: "result": true
2016-11-06T05:08:06.783336+00:00 app[web.1]: }
2016-11-06T05:08:06.783337+00:00 app[web.1]: } X-Parse-Push-Status-Id=NbZCxyCOgc, result=true
2016-11-06T05:08:06.787076+00:00 app[web.1]: Push ok
2016-11-06T05:08:06.788233+00:00 app[web.1]: verbose: sending push to 1 installations
2016-11-06T05:08:06.789569+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Notification transmitted to 443d4d770217648350c5c7cd7bb22d2da77223e23c06f3eb016b2e2ca76d6202
2016-11-06T05:08:06.790600+00:00 app[web.1]: verbose: sent push! 1 success, 0 failures
2016-11-06T05:08:06.867209+00:00 app[web.1]: ERR! parse-server-push-adapter APNS cannot find vaild connection for 443d4d770217648350c5c7cd7bb22d2da77223e23c06f3eb016b2e2ca76d6202
2016-11-06T05:08:06.868965+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Disconnected
2016-11-06T05:08:06.928135+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Connected
So it says it was sent successfully (we recieve NO notification to the device) and we get an ERR! parse-server.... for every device token registered from a valid device on a app distributed on Apple's TestFlight Application. I have read multiple posts regarding ways to fix this and have tried everything out there but nothing works. IF anyone has any insight on why this could be happening please let me know! I will be ever grateful
our index.js has the following config setup... we have checked the production cert and even rejected all our certs and generated new ones just to be sure.
push: {
ios: {
pfx: 'cert-prod.p12',
bundleId: 'a.bundle.id'
}
}
I had this issue recently. Did you make sure the path to the pfx file is a complete path? I used the path module to remedy this:
var path = require('path');
opts.push.ios = {
// The filename of private key and certificate in PFX
pfx: path.join(__dirname, env.IOS_PUSH_PFX),
bundleId: env.IOS_BUNDLE_ID
}
Reference from https://github.com/ParsePlatform/parse-server/issues/3025#issuecomment-258957541

Resources