assaf / node-passbook

iOS Passbook for the Node hacker
MIT License
280 stars 73 forks source link

When rendering a pass through a response, the callback never gets called on success #12

Open mikeseghers opened 10 years ago

mikeseghers commented 10 years ago

When I render a pass through the .render(response, callback) method, the callback only gets called when something fails.

I thing the issue is that the "end" event is never emitted when the zip file has been created successfully. I've done some testing, and I've seen that the "end" event on the zip variable is never fired neither.

When I add an zip.emit("end") after adding the signature is added to the zip. Still nothing happens. When i move the zip.on("end", ...) outside of the callback passed to the self.signZip(...) method, my original callback gets called.

here is how I changed the code:

in pass.js:

within the pipe function:

function doneWithImages() {
    if (lastError) {
      zip.close();
      self.emit("error", lastError);
    } else {

//This was moved up
        zip.on("end", function() {
          self.emit("end");
        });
        zip.on("error", function(error) {
          self.emit("error", error);
        });
//End of change
      self.signZip(zip, manifest, function(error) {
        zip.close();
        //the above code was taken from here
      });
    }
  }

within the signZip function:

signManifest(this.template, json, function(error, signature) {
    if (!error) {
      zip.addFile("signature").end(signature);
//The next line was added
zip.emit("end");
    }
    callback(error);
  });
kgjohnso commented 9 years ago

+1

and thanks @mikeseghers for finding the solution