aboutsummaryrefslogtreecommitdiff
path: root/lib/serve.js
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-01-26 15:02:43 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-01-28 19:55:19 -1000
commitf002fac331c79baff7fde57899d76be0410ffe10 (patch)
tree1bed964873e117277843101c5dfaf57aca2a889d /lib/serve.js
parent05865706da36f4f3f7c2d03df4065ffdd9911a69 (diff)
downloadpatchfoo-f002fac331c79baff7fde57899d76be0410ffe10.tar.gz
patchfoo-f002fac331c79baff7fde57899d76be0410ffe10.zip
Add /script route
Diffstat (limited to 'lib/serve.js')
-rw-r--r--lib/serve.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/serve.js b/lib/serve.js
index e3901a0..30b529b 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -390,6 +390,7 @@ Serve.prototype.path = function (url) {
case '/shard': return this.shard(m[2])
case '/zip': return this.zip(m[2])
case '/web': return this.web(m[2])
+ case '/script': return this.script(m[2])
}
return this.respond(404, 'Not found')
}
@@ -3043,6 +3044,23 @@ Serve.prototype.web = function (url) {
})
}
+Serve.prototype.script = function (url) {
+ var self = this
+ var filepath = url.split('?')[0]
+ this.app.getScript(filepath, function (err, fn) {
+ try {
+ if (err) throw err
+ fn(self)
+ } catch(e) {
+ return pull(
+ pull.once(u.renderError(e).outerHTML),
+ self.wrapPage('local: ' + path),
+ self.respondSink(400)
+ )
+ }
+ })
+}
+
// wrap a binary source and render it or turn into an embed
Serve.prototype.wrapBinary = function (opts) {
var self = this