Skip to content

Commit 0f7bfc8

Browse files
Refactor/expand SolidHost.parseTargetUrl()
1 parent 2ec6ed2 commit 0f7bfc8

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

lib/models/solid-host.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class SolidHost {
3131
this.live = options.live
3232
this.root = options.root
3333
this.multiuser = options.multiuser
34+
this.webid = options.webid
3435
}
3536

3637
/**
@@ -117,18 +118,36 @@ class SolidHost {
117118
return cookieDomain
118119
}
119120

121+
/**
122+
* Returns the protocol for an incoming request ('http' or 'https')
123+
* @returns {string}
124+
*/
125+
protocol (req) {
126+
// Obtain the protocol from the configured server URI
127+
// (in case the server is running behind a reverse proxy)
128+
const protocol = this.serverUri.replace(/:.*/, '')
129+
return protocol || req.protocol
130+
}
131+
120132
/**
121133
* Taken from utils.getBaseUri()
122134
*
123135
* @param req {IncomingRequest}
124136
*
125137
* @returns {string}
126138
*/
127-
parseTargetUrl (req) {
128-
const protocol = this.serverUri.replace(/:.*/, '')
139+
getBaseUri (req) {
140+
return this.protocol(req) + '://' + req.get('host')
141+
}
129142

143+
/**
144+
* @param req {IncomingRequest}
145+
*
146+
* @returns {string}
147+
*/
148+
parseTargetUrl (req) {
130149
return url.format({
131-
protocol: protocol || req.protocol,
150+
protocol: this.protocol(req),
132151
host: req.get('host'),
133152
pathname: url.resolve(req.baseUrl, req.path),
134153
query: req.query

lib/server-config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ function hostConfigFor (argv) {
2828
serverUri: argv.serverUri,
2929
live: argv.live,
3030
root: argv.root,
31-
multiuser: argv.multiuser
31+
multiuser: argv.multiuser,
32+
webid: argv.webid
3233
}
3334
}
3435

0 commit comments

Comments
 (0)