aboutsummaryrefslogtreecommitdiff
path: root/lib/serve.js
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-04-13 10:06:10 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-04-13 10:07:27 -1000
commit47422c2f0b901f475d35e7b15cc1356617b2c7ea (patch)
treef4a1e92799f1d3775ee2779e9138033a81694d75 /lib/serve.js
parent4d1395740db1ddebaa558f2c27d29ab772e74936 (diff)
downloadpatchfoo-47422c2f0b901f475d35e7b15cc1356617b2c7ea.tar.gz
patchfoo-47422c2f0b901f475d35e7b15cc1356617b2c7ea.zip
Use Host header in publishguard redirect base
so can redirect to e.g. 'localhost' instead of '[::1]'
Diffstat (limited to 'lib/serve.js')
-rw-r--r--lib/serve.js33
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/serve.js b/lib/serve.js
index 353b60a..a965573 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -64,6 +64,8 @@ function Serve(app, req, res) {
this.req = req
this.res = res
this.startDate = new Date()
+ var hostname = req.headers.host || app.hostname
+ this.baseUrl = 'http://' + hostname + (app.opts.base || '/')
}
Serve.prototype.go = function () {
@@ -333,7 +335,7 @@ Serve.prototype.publish = function (content, cb) {
})
done(function (err) {
if (err) return cb(err)
- self.app.publishMayRedirect(content, function (err, msg) {
+ self.publishMayRedirect(content, function (err, msg) {
if (err) return cb(err)
delete self.data.text
delete self.data.recps
@@ -342,6 +344,35 @@ Serve.prototype.publish = function (content, cb) {
})
}
+Serve.prototype.publishMayRedirect = function (content, cb) {
+ var publishguard = this.app.sbot.publishguard
+ if (Array.isArray(content.recps)) {
+ var recps = content.recps.map(u.linkDest)
+ if (publishguard && publishguard.privatePublishGetUrl) {
+ return publishguard.privatePublishGetUrl({
+ content: content,
+ recps: recps,
+ redirectBase: this.baseUrl
+ }, onPublishGetUrl)
+ } else {
+ this.app.privatePublish(content, recps, cb)
+ }
+ } else {
+ if (publishguard && publishguard.publishGetUrl) {
+ publishguard.publishGetUrl({
+ content: content,
+ redirectBase: this.baseUrl
+ }, onPublishGetUrl)
+ } else {
+ this.app.sbot.publish(content, cb)
+ }
+ }
+ function onPublishGetUrl(err, url) {
+ if (err) return cb(err)
+ cb({redirectUrl: url})
+ }
+}
+
Serve.prototype.handle = function () {
var m = urlIdRegex.exec(this.req.url)
this.query = m[5] ? qs.parse(m[5]) : {}