Skip to content

Commit 88c1faf

Browse files
committed
Move calls from utils#getFullUri to ResourceMapper
1 parent b3d6448 commit 88c1faf

File tree

6 files changed

+11
-28
lines changed

6 files changed

+11
-28
lines changed

lib/capability-discovery.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @module capability-discovery
44
*/
55
const express = require('express')
6-
const util = require('./utils')
76

87
const serviceConfigDefaults = {
98
'api': {
@@ -47,7 +46,7 @@ function capabilityDiscovery () {
4746
function serviceCapabilityDocument (serviceConfig) {
4847
return (req, res) => {
4948
// Add the server root url
50-
serviceConfig.root = util.getFullUri(req) // TODO make sure we align with the rest
49+
serviceConfig.root = req.app.locals.ldp.resourceMapper.getBaseUrl(req.hostname, req.path)
5150
// Add the 'apps' urls section
5251
serviceConfig.apps = req.app.locals.appUrls
5352
res.json(serviceConfig)

lib/handlers/get.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const debug = require('debug')('solid:get')
1111
const debugGlob = require('debug')('solid:glob')
1212
const allow = require('./allow')
1313

14-
const utils = require('../utils.js')
1514
const translate = require('../utils.js').translate
1615
const error = require('../http-error')
1716

@@ -21,7 +20,7 @@ async function handler (req, res, next) {
2120
const ldp = req.app.locals.ldp
2221
const includeBody = req.method === 'GET'
2322
const negotiator = new Negotiator(req)
24-
const baseUri = utils.getFullUri(req)
23+
const baseUri = ldp.resourceMapper.getBaseUrl(req.hostname, req.path)
2524
const path = res.locals.path || req.path
2625
const requestedType = negotiator.mediaType()
2726
let possibleRDFType = negotiator.mediaType(RDFs)

lib/handlers/options.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const addLink = require('../header').addLink
2-
const utils = require('../utils')
32
const url = require('url')
43

54
module.exports = handler
@@ -23,7 +22,7 @@ function linkAuthProvider (req, res) {
2322
}
2423

2524
function linkServiceEndpoint (req, res) {
26-
let serviceEndpoint = url.resolve(utils.getFullUri(req), '.well-known/solid')
25+
let serviceEndpoint = url.resolve(req.app.locals.ldp.resourceMapper.getBaseUrl(req.hostname, req.path), '.well-known/solid')
2726
addLink(res, serviceEndpoint, 'service')
2827
}
2928

lib/header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function addPermissions (req, res, next) {
103103
if (!acl) return next()
104104

105105
// Turn permissions for the public and the user into a header
106-
const resource = utils.getFullUri(req)
106+
const resource = req.app.locals.ldp.resourceMapper.getBaseUrl(req.hostname, req.path)
107107
Promise.all([
108108
getPermissionsFor(acl, null, resource),
109109
getPermissionsFor(acl, session.userId, resource)

lib/resource-mapper.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,14 @@ class ResourceMapper {
7878
}
7979

8080
// Gets the base URL for the given hostname
81-
getBaseUrl (hostname) {
82-
return !this._includeHost ? this._rootUrl
81+
// Optionally, a pathname may be passed that will be appended to the baseUrl.
82+
getBaseUrl (hostname, pathname) {
83+
let baseUrl = !this._includeHost ? this._rootUrl
8384
: `${this._protocol}//${hostname}${this._port}${this._rootUrl}`
85+
if (pathname) {
86+
baseUrl += pathname
87+
}
88+
return baseUrl
8489
}
8590

8691
// Determine the full file path corresponding to a URL

lib/utils.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module.exports.getBaseUri = getBaseUri
22
module.exports.pathBasename = pathBasename
3-
module.exports.getFullUri = getFullUri
43
module.exports.hasSuffix = hasSuffix
54
module.exports.serialize = serialize
65
module.exports.translate = translate
@@ -80,24 +79,6 @@ function getBaseUri (req) {
8079
return `${protocol || req.protocol}://${req.get('host')}`
8180
}
8281

83-
/**
84-
* Composes and returns the fully-qualified URI for the request, to be used
85-
* as a base URI for RDF parsing or serialization. For example, if a request
86-
* is to `Host: example.com`, `GET /files/` using the `https:` protocol,
87-
* then:
88-
*
89-
* ```
90-
* getFullUri(req) // -> 'https://example.com/files/'
91-
* ```
92-
*
93-
* @param req {IncomingMessage}
94-
*
95-
* @return {string}
96-
*/
97-
function getFullUri (req) {
98-
return getBaseUri(req) + url.resolve(req.baseUrl, req.path)
99-
}
100-
10182
function pathBasename (fullpath) {
10283
let bname = ''
10384
if (fullpath) {

0 commit comments

Comments
 (0)