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 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib') 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 -- cgit v1.2.3