Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2014-04-23 14:31:25 +0400
committerFeross Aboukhadijeh <feross@feross.org>2014-04-23 14:31:25 +0400
commit6873784f59df81cacd0895a987a17d08dad809b3 (patch)
treecbe8eb7e7f1890c8dfbe0dd091427269303b1faa /index.js
parent5d4ec711b6acea400be3dfca1c9b6860bf4329bf (diff)
don't 404 if server is not ready, just wait
Diffstat (limited to 'index.js')
-rw-r--r--index.js7
1 files changed, 6 insertions, 1 deletions
diff --git a/index.js b/index.js
index 884b861..7d5e579 100644
--- a/index.js
+++ b/index.js
@@ -90,6 +90,11 @@ WebTorrent.prototype._onReady = function () {
WebTorrent.prototype._onRequest = function (req, res) {
var self = this
+
+ if (!self._ready) {
+ return self.once('ready', self._onRequest.bind(self, req, res))
+ }
+
var u = url.parse(req.url)
if (u.pathname === '/favicon.ico') {
@@ -101,7 +106,7 @@ WebTorrent.prototype._onRequest = function (req, res) {
var i = Number(u.pathname.slice(1))
- if (isNaN(i) || i >= e.files.length || !self._ready) {
+ if (isNaN(i) || i >= e.files.length) {
res.statusCode = 404
return res.end()
}