{"action":"created","issue":{"url":"https://api.github.com/repos/krakenjs/kraken-js/issues/326","labels_url":"https://api.github.com/repos/krakenjs/kraken-js/issues/326/labels{/name}","comments_url":"https://api.github.com/repos/krakenjs/kraken-js/issues/326/comments","events_url":"https://api.github.com/repos/krakenjs/kraken-js/issues/326/events","html_url":"https://github.com/krakenjs/kraken-js/issues/326","id":55442901,"number":326,"title":"\"Server is Starting\" when using Phusion Passenger","user":{"login":"frnco","id":1730340,"avatar_url":"https://avatars.githubusercontent.com/u/1730340?v=3","gravatar_id":"","url":"https://api.github.com/users/frnco","html_url":"https://github.com/frnco","followers_url":"https://api.github.com/users/frnco/followers","following_url":"https://api.github.com/users/frnco/following{/other_user}","gists_url":"https://api.github.com/users/frnco/gists{/gist_id}","starred_url":"https://api.github.com/users/frnco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frnco/subscriptions","organizations_url":"https://api.github.com/users/frnco/orgs","repos_url":"https://api.github.com/users/frnco/repos","events_url":"https://api.github.com/users/frnco/events{/privacy}","received_events_url":"https://api.github.com/users/frnco/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-01-26T03:10:53Z","updated_at":"2015-01-26T05:01:26Z","closed_at":null,"body":"This piece of code breaks flows with Phusion Passenger, since Passenger starts processes when requests are made:\r\n\r\n        parent.use(function startup(req, res, next) {\r\n            if (deferred.promise.isFulfilled()) {\r\n                next();\r\n                return;\r\n            }z\r\n            res.send(503, 'Server is starting.');\r\n        });\r\n\r\n\r\nWouldn't it be better to check on promises and wait until they complete if needed?\r\n\r\nNot the easiest way out, I'm pretty sure, but I think it's better for KrakenJS if it can run amazingly with lots of tools, and Passenger is a pretty good tool for deloyment.\r\n\r\n\r\n\r\nAlso, not directly related and I know off-topic is kinda bad, but I couldn't find much about deploying. I'll possibly create another issue or do a Pull Request on the docs about that (So please let's not fill this thread with deploying stuff), but it won't hurt to ask opinions on the matter, maybe I just need some pointing in the right direction.\r\n\r\n\r\nThanks in advance. :D"},"comment":{"url":"https://api.github.com/repos/krakenjs/kraken-js/issues/comments/71414998","html_url":"https://github.com/krakenjs/kraken-js/issues/326#issuecomment-71414998","issue_url":"https://api.github.com/repos/krakenjs/kraken-js/issues/326","id":71414998,"user":{"login":"jasisk","id":62923,"avatar_url":"https://avatars.githubusercontent.com/u/62923?v=3","gravatar_id":"","url":"https://api.github.com/users/jasisk","html_url":"https://github.com/jasisk","followers_url":"https://api.github.com/users/jasisk/followers","following_url":"https://api.github.com/users/jasisk/following{/other_user}","gists_url":"https://api.github.com/users/jasisk/gists{/gist_id}","starred_url":"https://api.github.com/users/jasisk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasisk/subscriptions","organizations_url":"https://api.github.com/users/jasisk/orgs","repos_url":"https://api.github.com/users/jasisk/repos","events_url":"https://api.github.com/users/jasisk/events{/privacy}","received_events_url":"https://api.github.com/users/jasisk/received_events","type":"User","site_admin":false},"created_at":"2015-01-26T05:01:26Z","updated_at":"2015-01-26T05:01:26Z","body":"Hey @frnco. Thanks for the kind words. We really appreciate it.\r\n\r\nIf you look just above the block of code you mention, you'll find that when the promise [is resolved](https://github.com/krakenjs/kraken-js/blob/eb84151171fea26f3a8a0519724f98d7b83d2307/index.js#L68), we [emit a `start` event](https://github.com/krakenjs/kraken-js/blob/eb84151171fea26f3a8a0519724f98d7b83d2307/index.js#L61). You can defer binding until that point such that there will never be a case when the promise in unfulfilled and bound.\r\n\r\nSince Passenger hooks that first call to listen, I believe that will take care of the issue. I'm unable to run Passenger at the moment, but give something like this a shot:\r\n\r\n``` js\r\n'use strict';\r\nvar kraken = require('kraken-js');\r\nvar express = require('express');\r\nvar app = express();\r\n\r\napp.use(kraken());\r\n\r\napp.on('start', function () {\r\n  app.listen(3000, function () {\r\n    console.log('listening ...');\r\n  });\r\n});\r\n```\r\n"}}