Skip to content

Commit 7039759

Browse files
RubenVerborghrubensworks
authored andcommitted
Add resourcMapper field to LDP.
1 parent b568142 commit 7039759

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

lib/create-app.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const options = require('./handlers/options')
2323
const debug = require('./debug').authentication
2424
const path = require('path')
2525
const { routeResolvedFile } = require('./utils')
26+
const LegacyResourceMapper = require('./legacy-resource-mapper')
2627

2728
const corsSettings = cors({
2829
methods: [
@@ -41,6 +42,12 @@ function createApp (argv = {}) {
4142

4243
argv.host = SolidHost.from({ port: argv.port, serverUri: argv.serverUri })
4344

45+
argv.resourceMapper = new LegacyResourceMapper({
46+
rootUrl: argv.serverUri,
47+
rootPath: argv.root,
48+
includeHost: argv.multiuser
49+
})
50+
4451
const configPath = config.initConfigDir(argv)
4552
argv.templates = config.initTemplateDirs(configPath)
4653

lib/resource-mapper.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ const readdir = promisify(fs.readdir)
88
// following the principles of the “sweet spot” discussed in
99
// https://www.w3.org/DesignIssues/HTTPFilenameMapping.html
1010
class ResourceMapper {
11-
constructor ({ rootUrl, rootPath, includeHost, defaultContentType = 'application/octet-stream' }) {
11+
constructor ({
12+
rootUrl = 'https://localhost:8443/',
13+
rootPath = '/tmp/',
14+
includeHost = false,
15+
defaultContentType = 'application/octet-stream'
16+
}) {
1217
this._rootUrl = this._removeTrailingSlash(rootUrl)
1318
this._rootPath = this._removeTrailingSlash(rootPath)
1419
this._includeHost = includeHost

test/integration/ldp-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var LDP = require('../../lib/ldp')
55
var path = require('path')
66
var stringToStream = require('../../lib/utils').stringToStream
77
var randomBytes = require('randombytes')
8+
var LegacyResourceMapper = require('../../lib/legacy-resource-mapper')
89

910
// Helper functions for the FS
1011
var rm = require('./../utils').rm
@@ -14,8 +15,15 @@ var read = require('./../utils').read
1415
var fs = require('fs')
1516

1617
describe('LDP', function () {
18+
var root = path.join(__dirname, '..')
19+
20+
var resourceMapper = new LegacyResourceMapper({
21+
rootPath: root
22+
})
23+
1724
var ldp = new LDP({
1825
root: path.join(__dirname, '..'),
26+
resourceMapper,
1927
serverUri: 'https://localhost',
2028
multiuser: true,
2129
webid: false

0 commit comments

Comments
 (0)