diff options
author | Stephen Whitmore <sww@eight45.net> | 2018-04-16 12:05:59 -0700 |
---|---|---|
committer | Stephen Whitmore <sww@eight45.net> | 2018-04-16 13:27:38 -0700 |
commit | b037d20c242f538c48bf87cd060435b1e7cc2dc7 (patch) | |
tree | 5360ed29750ac4c5e31559f547ffce312b496081 /lib | |
parent | 4267334f1d3b50038c43b2f41e1fb5da2e9dbd6c (diff) | |
download | patchfoo-b037d20c242f538c48bf87cd060435b1e7cc2dc7.tar.gz patchfoo-b037d20c242f538c48bf87cd060435b1e7cc2dc7.zip |
feat: handle /web blob websites
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 |