From b037d20c242f538c48bf87cd060435b1e7cc2dc7 Mon Sep 17 00:00:00 2001 From: Stephen Whitmore Date: Mon, 16 Apr 2018 12:05:59 -0700 Subject: feat: handle /web blob websites --- lib/serve.js | 25 +++++++++++++++++++++++++ package.json | 1 + 2 files changed, 26 insertions(+) diff --git a/lib/serve.js b/lib/serve.js index 004079b..4c60cce 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -25,6 +25,7 @@ var Catch = require('pull-catch') var Diff = require('diff') var split = require('pull-split') var utf8 = require('pull-utf8-decoder') +var webresolve = require('ssb-web-resolver') module.exports = Serve @@ -352,6 +353,7 @@ Serve.prototype.path = function (url) { case '/npm-readme': return this.npmReadme(m[2]) case '/markdown': return this.markdown(m[2]) case '/zip': return this.zip(m[2]) + case '/web': return this.web(m[2]) } return this.respond(404, 'Not found') } @@ -2652,6 +2654,29 @@ Serve.prototype.zip = function (url) { }) } +Serve.prototype.web = function (url) { + var self = this + var id = decodeURIComponent(url.substr(1)) + + var components = url.split('/') + if (components[0] === '') components.shift() + components[0] = decodeURIComponent(components[0]) + + webresolve(this.app.sbot, components, function (err, res) { + if (err) { + return pull( + pull.once('ERROR:', err), + self.respondSink(404) + ) + } + + return pull( + pull.once(res), + self.respondSink(200) + ) + }) +} + // wrap a binary source and render it or turn into an embed Serve.prototype.wrapBinary = function (opts) { var self = this diff --git a/package.json b/package.json index 26dcfa2..20055ed 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "ssb-marked": "^0.7.1", "ssb-mentions": "http://localhost:8989/blobs/get/&GjuxknqKwJqHznKueFNCyIh52v1woz5PB41vqmoHfyM=.sha256", "ssb-sort": "^1.0.0", + "ssb-web-resolver": "^1.0.2", "stream-to-pull-stream": "^1.7.2", "unzip": "^0.1.11" }, -- cgit v1.2.3