aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/app.js30
-rw-r--r--lib/serve.js33
2 files changed, 33 insertions, 30 deletions
diff --git a/lib/app.js b/lib/app.js
index 25b5a94..cd4691f 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -54,8 +54,7 @@ function App(sbot, config) {
// sha256('peer-invites:DEVELOPMENT')
*/
- var host1 = /:/.test(this.host) ? '[' + this.host + ']' : this.host
- this.baseUrl = 'http://' + host1 + ':' + this.port
+ this.hostname = (/:/.test(this.host) ? '[' + this.host + ']' : this.host) + this.port
this.dir = path.join(config.path, conf.dir || 'patchfoo')
this.scriptDir = path.join(this.dir, conf.scriptDir || 'script')
this.draftsDir = path.join(this.dir, conf.draftsDir || 'drafts')
@@ -283,33 +282,6 @@ App.prototype.getMsgDecryptedOoo = function (key, cb) {
})
}
-App.prototype.publishMayRedirect = function (content, cb) {
- var publishguard = this.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)
- }
- this.privatePublish(content, recps, cb)
- } else {
- if (publishguard && publishguard.publishGetUrl) {
- return publishguard.publishGetUrl({
- content: content,
- redirectBase: this.baseUrl + '/'
- }, onPublishGetUrl)
- }
- this.sbot.publish(content, cb)
- }
- function onPublishGetUrl(err, url) {
- if (err) return cb(err)
- cb({redirectUrl: url})
- }
-}
-
App.prototype.privatePublish = function (content, recps, cb) {
if (this.private && typeof this.private.publish === 'function') {
return this.sbot.private.publish(content, recps, cb)
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]) : {}