Skip to content

Commit 3f63cb6

Browse files
committed
Use ResourceMapper instead of utils#getBaseUri
1 parent 3979844 commit 3f63cb6

File tree

4 files changed

+9
-23
lines changed

4 files changed

+9
-23
lines changed

lib/handlers/allow.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
module.exports = allow
22

33
const ACL = require('../acl-checker')
4-
const utils = require('../utils')
54
const debug = require('../debug.js').ACL
6-
const LegacyResourceMapper = require('../legacy-resource-mapper')
75

86
function allow (mode) {
97
return async function allowHandler (req, res, next) {
@@ -13,12 +11,7 @@ function allow (mode) {
1311
}
1412

1513
// Set up URL to filesystem mapping
16-
const rootUrl = utils.getBaseUri(req)
17-
const mapper = new LegacyResourceMapper({
18-
rootUrl,
19-
rootPath: ldp.root,
20-
includeHost: ldp.multiuser
21-
})
14+
const rootUrl = ldp.resourceMapper.getBaseUrl(req.hostname)
2215

2316
// Determine the actual path of the request
2417
// (This is used as an ugly hack to check the ACL status of other resources.)
@@ -44,7 +37,7 @@ function allow (mode) {
4437
req.acl = new ACL(rootUrl + reqPath, {
4538
origin: req.get('origin'),
4639
host: req.protocol + '://' + req.get('host'),
47-
fetch: fetchFromLdp(mapper, ldp),
40+
fetch: fetchFromLdp(ldp.resourceMapper, ldp),
4841
fetchGraph: (uri, options) => {
4942
// first try loading from local fs
5043
return ldp.getGraph(uri, options.contentType)

lib/handlers/copy.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module.exports = handler
33
const debug = require('../debug')
44
const error = require('../http-error')
55
const ldpCopy = require('../ldp-copy')
6-
const utils = require('../utils')
76
const url = require('url')
87

98
/**
@@ -20,10 +19,11 @@ async function handler (req, res, next) {
2019
return next(error(400, 'Source header required'))
2120
}
2221
const fromExternal = !!url.parse(copyFrom).hostname
23-
const serverRoot = utils.getBaseUri(req)
22+
const ldp = req.app.locals.ldp
23+
const serverRoot = ldp.resourceMapper.getBaseUrl(req.hostname)
2424
const copyFromUrl = fromExternal ? copyFrom : serverRoot + copyFrom
2525
const copyTo = res.locals.path || req.path
26-
const { path: copyToPath } = await req.app.locals.ldp.resourceMapper.mapUrlToFile({ url: req })
26+
const { path: copyToPath } = await ldp.resourceMapper.mapUrlToFile({ url: req })
2727
ldpCopy(copyToPath, copyFromUrl, function (err) {
2828
if (err) {
2929
let statusCode = err.statusCode || 500

lib/handlers/get.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const translate = require('../utils.js').translate
1616
const error = require('../http-error')
1717

1818
const RDFs = require('../ldp').RDF_MIME_TYPES
19-
const LegacyResourceMapper = require('../legacy-resource-mapper')
2019

2120
async function handler (req, res, next) {
2221
const ldp = req.app.locals.ldp
@@ -33,7 +32,7 @@ async function handler (req, res, next) {
3332

3433
// Set live updates
3534
if (ldp.live) {
36-
res.header('Updates-Via', utils.getBaseUri(req).replace(/^http/, 'ws'))
35+
res.header('Updates-Via', ldp.resourceMapper.getBaseUrl(req.hostname).replace(/^http/, 'ws'))
3736
}
3837

3938
debug(req.originalUrl + ' on ' + req.hostname)
@@ -77,13 +76,7 @@ async function handler (req, res, next) {
7776
// Till here it must exist
7877
if (!includeBody) {
7978
debug('HEAD only')
80-
const rootUrl = utils.getBaseUri(req)
81-
const mapper = new LegacyResourceMapper({
82-
rootUrl,
83-
rootPath: ldp.root,
84-
includeHost: ldp.multiuser
85-
})
86-
const mappedFile = await mapper.mapFileToUrl({ path })
79+
const mappedFile = await ldp.resourceMapper.mapFileToUrl({ path })
8780
contentType = mappedFile.contentType
8881
res.setHeader('Content-Type', contentType)
8982
res.status(200).send('OK')

test/integration/http-copy-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var rm = require('./../utils').rm
88
var solidServer = require('../../index')
99

1010
describe('HTTP COPY API', function () {
11-
var address = 'https://localhost:3456'
11+
var address = 'https://localhost:8443'
1212

1313
var ldpHttpsServer
1414
var ldp = solidServer.createServer({
@@ -19,7 +19,7 @@ describe('HTTP COPY API', function () {
1919
})
2020

2121
before(function (done) {
22-
ldpHttpsServer = ldp.listen(3456, done)
22+
ldpHttpsServer = ldp.listen(8443, done)
2323
})
2424

2525
after(function () {

0 commit comments

Comments
 (0)