git ssb

3+

cel / ssb-npm-registry



Commit 216ac844c0cba7f0570d5f98f0d5c49241fdc309

Link to blobs from ssb-ws for local requests

cel committed on 8/31/2018, 2:53:35 AM
Parent: fa946a64685781d58a9266937da0e1d9c30a20d6

Files changed

index.jschanged
index.jsView
@@ -339,8 +339,12 @@
339339 this.fetchAll = this.npmConfig.fetchAll
340340 this.needShasum = this.npmConfig.needShasum
341341 this.getMsg = memo({cache: lru(100)}, this.getMsg)
342342 this.getFeedName = memo({cache: lru(100)}, this.getFeedName)
343 + if (sbot.ws) {
344 + var wsPort = config.ws && Number(config.ws.port) || '8989'
345 + this.wsUrl = 'http://localhost:' + wsPort
346 + }
343347 }
344348
345349 SsbNpmRegistryServer.prototype = Object.create(http.Server.prototype)
346350 SsbNpmRegistryServer.prototype.constructor = SsbNpmRegistryServer
@@ -495,10 +499,22 @@
495499 var hostname = req.headers.host
496500 || (formatHost(req.socket.localAddress) + ':' + req.socket.localPort)
497501 this.baseUrl = 'http://' + hostname
498502 }
503 +
504 + // prefer serving blobs from ssb-ws, for consistency of tarball URLs.
505 + this.blobBaseUrl = this.server.wsUrl && this.isLocal()
506 + ? this.server.wsUrl + '/blobs/get/'
507 + : this.baseUrl + '/-/blobs/get/'
499508 }
500509
510 +Req.prototype.isLocal = function () {
511 + var remoteAddr = this.req.socket.remoteAddress
512 + return remoteAddr === '::1'
513 + || remoteAddr === '::ffff:127.0.0.1'
514 + || remoteAddr === '127.0.0.1'
515 +}
516 +
501517 Req.prototype.serve = function () {
502518 console.log(this.req.method, this.req.url, formatHost(this.req.socket.remoteAddress))
503519 this.res.setTimeout(0)
504520 var pathname = this.req.url.replace(/\?.*/, '')
@@ -559,9 +575,9 @@
559575 var m = /^&([^.]+)\.([a-z0-9]+)$/.exec(id)
560576 if (!m) throw new Error('bad blob id: ' + id)
561577 return {
562578 integrity: m[2] + '-' + m[1],
563- tarball: this.baseUrl + '/-/blobs/get/' + id
579 + tarball: this.blobBaseUrl + id
564580 }
565581 }
566582
567583 Req.prototype.getMsgIdForBlobMention = function (blobId, feedId, cb) {

Built with git-ssb-web