diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/serve.js | 25 |
1 files changed, 25 insertions, 0 deletions
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 |