Skip to content

Commit f013adb

Browse files
author
nicola
committed
webid disabled by default and uriBase/fileBase to uri/base
1 parent eb81af9 commit f013adb

15 files changed

Lines changed: 66 additions & 68 deletions

File tree

‎Makefile‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# see also JSON validator http://jsonformatter.curiousconcept.com for the package.json file
22

33
run-for-test:
4-
node bin/ldnode.js -p 3456 -v --uriBase http://localhost:3456/test/ --fileBase `pwd`/test/
4+
node bin/ldnode.js -p 3456 -v --uri http://localhost:3456/test/ --base `pwd`/test/
55

66
run-for-test-login:
7-
node bin/ldnode.js -p 3456 -v --webid --uriBase https://localhost:3456/test/ --fileBase `pwd`/test/
7+
node bin/ldnode.js -p 3456 -v --webid --uri https://localhost:3456/test/ --base `pwd`/test/
88

99
run-for-live-test:
1010
NODE_PATH=.:../tabulator-firefox/content/js/rdf/dist/ node server.js \
11-
p 3456 -v --live --uriBase http://localhost:3456/test/ --fileBase `pwd`/test/
11+
p 3456 -v --live --uri http://localhost:3456/test/ --base `pwd`/test/
1212

1313
run-for-test-special:
1414
NODE_PATH=.:../tabulator-firefox/content/js/rdf/dist/ node server.js \
15-
-p 3456 -v --uriBase http://localhost:3456/test/ --fileBase `pwd`/test/
15+
-p 3456 -v --uri http://localhost:3456/test/ --base `pwd`/test/
1616

1717
# use --debug to run or --debug-brk to break immediately
1818
run-for-test-special-debug:
1919
NODE_PATH=.:../tabulator-firefox/content/js/rdf/dist/ node --debug-brk server.js \
20-
-p 3456 -v --uriBase http://localhost:3456/test/ --fileBase `pwd`/test/
20+
-p 3456 -v --uri http://localhost:3456/test/ --base `pwd`/test/
2121
# Then run node-inspector and open Chrome as it suggests
2222
# (If necessary, npm install -g node-inspector)
2323

‎README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ npm install
3131
var ldnode = require('ldnode')
3232

3333
var ldp = ldnode.createServer({
34-
uriBase: "http://example.com/test/",
35-
fileBase: __dirname + '/test/'
34+
uri: "http://example.com/test/",
35+
base: __dirname + '/test/'
3636
})
3737
ldp.listen(1234, function() {
3838
// Started Linked Data Platform
@@ -73,8 +73,8 @@ The command line tool has the following options
7373
usage: ldnode [path] [options]
7474

7575
options:
76-
--uriBase Address, port, and default path of the server. (Example: http://localhost:3000/test/)
77-
--fileBase Base location to serve resources. Requests whose paths do not have fileBase as a prefix will be ignored
76+
--uri Address, port, and default path of the server. (Example: http://localhost:3000/test/)
77+
--base Base location to serve resources. Requests whose paths do not have base as a prefix will be ignored
7878
--live Offer and support live updates
7979
-p Port to use
8080
-v Log messages to console

‎acl.js‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ function allow(mode, req, res) {
2222

2323
var accessType = "accessTo";
2424

25-
var filepath = file.uriToFilename(req.path, options.fileBase);
26-
var relativePath = file.uriToRelativeFilename(req.path, options.fileBase);
25+
var filepath = file.uriToFilename(req.path, options.base);
26+
var relativePath = file.uriToRelativeFilename(req.path, options.base);
2727
var depth = relativePath.split('/');
2828

2929
//Handle glob requests
@@ -37,8 +37,8 @@ function allow(mode, req, res) {
3737
for (var i = 0; i < depth.length; i++) {
3838
var pathAcl = S(filepath).endsWith(aclExtension) ?
3939
filepath : filepath + aclExtension;
40-
var pathUri = file.filenameToBaseUri(filepath, options.uriBase, options.fileBase);
41-
relativePath = path.relative(options.fileBase, filepath);
40+
var pathUri = file.filenameToBaseUri(filepath, options.uri, options.base);
41+
relativePath = path.relative(options.base, filepath);
4242

4343
debug("Checking " + accessType + "<" + mode + "> to " +
4444
pathUri + " for WebID: " + req.session.userId);
@@ -203,19 +203,19 @@ function allow(mode, req, res) {
203203
accessType = "defaultForNew";
204204
if (i === 0) {
205205
if (path.dirname(path.dirname(relativePath)) == '.') {
206-
filepath = options.fileBase;
206+
filepath = options.base;
207207
} else if (S(relativePath).endsWith("/")) {
208-
filepath = options.fileBase + path.dirname(path.dirname(relativePath));
208+
filepath = options.base + path.dirname(path.dirname(relativePath));
209209
} else {
210-
filepath = options.fileBase + path.dirname(relativePath);
210+
filepath = options.base + path.dirname(relativePath);
211211
}
212212
} else {
213213
if (relativePath.length === 0) {
214214
break;
215215
} else if (path.dirname(path.dirname(relativePath)) === '.') {
216-
filepath = options.fileBase;
216+
filepath = options.base;
217217
} else {
218-
filepath = options.fileBase + path.dirname(path.dirname(relativePath));
218+
filepath = options.base + path.dirname(path.dirname(relativePath));
219219
}
220220
}
221221

‎bin/ldnode.js‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ var argv = require('nomnom')
1919
});
2020
}
2121
})
22-
.option('uriBase', {
23-
full: 'uri',
22+
.option('uri', {
2423
abbr: 'u',
2524
help: 'Default address of the server (e.g. http[s]://host:port/path)'
2625
})
27-
.option('fileBase', {
26+
.option('base', {
2827
abbr: 'b',
29-
full: 'path',
28+
full: 'base',
3029
help: 'Base location to serve resources'
3130
})
3231
.option('port', {
@@ -47,9 +46,9 @@ var argv = require('nomnom')
4746
help: 'Path to the ssl cert',
4847
abbr: 'C'
4948
})
50-
.option('noWebid', {
51-
help: 'Disable WebID+TLS authentication',
52-
full: 'no-webid',
49+
.option('webid', {
50+
help: 'Enable WebID+TLS authentication',
51+
full: 'webid',
5352
flag: true
5453
})
5554
.option('secret', {
@@ -70,7 +69,6 @@ if (argv.version) {
7069
}
7170

7271
// Set up --no-*
73-
argv.webid = !argv.noWebid;
7472
argv.live = !argv.noLive;
7573

7674
// Set up debug environment

‎container.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var addUriTriple = function(kb, s, o, p) {
1919
var turtleExtension = ".ttl";
2020

2121
function createRootContainer(options) {
22-
if (!metadata.hasContainerMetadata(options.fileBase)) {
22+
if (!metadata.hasContainerMetadata(options.base)) {
2323
var rootContainer = $rdf.graph();
2424
addUriTriple(rootContainer, options.pathStart,
2525
rdfVocab.type, ldpVocab.Container);
@@ -30,13 +30,13 @@ function createRootContainer(options) {
3030
'"Root Container"');
3131
var serializedContainer = $rdf.serialize(undefined, rootContainer,
3232
options.pathStart, 'text/turtle');
33-
metadata.writeContainerMetadata(options.fileBase,
33+
metadata.writeContainerMetadata(options.base,
3434
serializedContainer, function(err) {
3535
if (err) {
3636
//TODO handle error
3737
debug("Could not write root container");
3838
} else {
39-
debug("Wrote root container to " + options.fileBase);
39+
debug("Wrote root container to " + options.base);
4040
}
4141
});
4242
}
@@ -74,10 +74,10 @@ function releaseResourceUri(options, uri) {
7474
}
7575

7676
function createNewResource(options, resourcePath, resourceGraph, callback) {
77-
var resourceURI = path.relative(options.fileBase, resourcePath);
77+
var resourceURI = path.relative(options.base, resourcePath);
7878
//TODO write files with relative URIS.
7979
var rawResource = $rdf.serialize(undefined,
80-
resourceGraph, options.uriBase + resourceURI, 'text/turtle');
80+
resourceGraph, options.uri + resourceURI, 'text/turtle');
8181
debug("Writing new resource to " + resourcePath);
8282
debug("Resource:\n" + rawResource);
8383
fs.writeFile(resourcePath, rawResource, writeResourceCallback);
@@ -103,7 +103,7 @@ function createNewContainer(options, containerPath, containerGraph, callback) {
103103
return callback(err);
104104
} else {
105105
var rawContainer = $rdf.serialize(undefined, containerGraph,
106-
options.uriBase, 'text/turtle');
106+
options.uri, 'text/turtle');
107107
debug("rawContainer " + rawContainer);
108108
metadata.writeContainerMetadata(containerPath, rawContainer,
109109
writeContainerCallback);

‎fileStore.js‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ var fs = require('fs');
55
var path = require('path');
66
var S = require('string');
77

8-
function uriToFilename(uri, fileBase) {
9-
var filename = path.join(fileBase, uri);
8+
function uriToFilename(uri, base) {
9+
var filename = path.join(base, uri);
1010
// Make sure filename ends with '/' if filename exists and is a directory.
1111
try {
1212
var fileStats = fs.statSync(filename);
@@ -19,15 +19,15 @@ function uriToFilename(uri, fileBase) {
1919
return filename;
2020
}
2121

22-
function uriToRelativeFilename(uri, fileBase) {
23-
var filename = uriToFilename(uri, fileBase);
24-
var relative = path.relative(fileBase, filename);
22+
function uriToRelativeFilename(uri, base) {
23+
var filename = uriToFilename(uri, base);
24+
var relative = path.relative(base, filename);
2525
return relative;
2626
}
2727

28-
function filenameToBaseUri(filename, uriBase, fileBase) {
29-
var uriPath = S(filename).strip(fileBase).toString();
30-
return uriBase + uriPath;
28+
function filenameToBaseUri(filename, uri, base) {
29+
var uriPath = S(filename).strip(base).toString();
30+
return uri + uriPath;
3131
}
3232

3333
exports.uriToFilename = uriToFilename;

‎handlers/delete.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var metadata = require('../metadata.js');
1010
function handler(req, res) {
1111
var options = req.app.locals.ldp;
1212
debug('DELETE -- ' + req.path);
13-
var filename = file.uriToFilename(req.path, options.fileBase);
13+
var filename = file.uriToFilename(req.path, options.base);
1414
fs.stat(filename, function(err, stats) {
1515
if (err) {
1616
debug("DELETE -- unlink() error: " + err);

‎handlers/get.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function get(req, res, includeBody) {
4646
debug('HEAD -- ' + req.path);
4747
}
4848

49-
var filename = file.uriToFilename(req.path, options.fileBase);
49+
var filename = file.uriToFilename(req.path, options.base);
5050
fs.stat(filename, function(err, stats) {
5151
if (err) {
5252
if (glob.hasMagic(filename)) {
@@ -118,7 +118,7 @@ function get(req, res, includeBody) {
118118
try {
119119
var fileData = fs.readFileSync(match,
120120
{encoding: "utf8"});
121-
var baseUri = file.filenameToBaseUri(match, options.uriBase, options.fileBase);
121+
var baseUri = file.filenameToBaseUri(match, options.uri, options.base);
122122
//TODO integrate ACL
123123
if (S(match).endsWith(".ttl") && aclAllow(match)) {
124124
$rdf.parse(fileData, globGraph, baseUri,
@@ -140,7 +140,7 @@ function get(req, res, includeBody) {
140140
return true;
141141
} else {
142142
var relativePath = '/' +
143-
path.relative(options.fileBase, match);
143+
path.relative(options.base, match);
144144
req.path = relativePath;
145145
var allow = acl.allow("Read", req, res);
146146
if (allow.status === 200) {
@@ -153,7 +153,7 @@ function get(req, res, includeBody) {
153153

154154
function parseLinkedData(turtleData) {
155155
var accept = header.parseAcceptHeader(req);
156-
var baseUri = file.filenameToBaseUri(filename, options.uriBase, options.fileBase);
156+
var baseUri = file.filenameToBaseUri(filename, options.uri, options.base);
157157

158158
// Handle Turtle Accept header
159159
if (accept === undefined || accept === null) {
@@ -190,7 +190,7 @@ function get(req, res, includeBody) {
190190

191191
function parseContainer(containerData) {
192192
//Handle other file types
193-
var baseUri = file.filenameToBaseUri(filename, options.uriBase, options.fileBase);
193+
var baseUri = file.filenameToBaseUri(filename, options.uri, options.base);
194194
var resourceGraph = $rdf.graph();
195195
try {
196196
$rdf.parse(containerData, resourceGraph, baseUri, 'text/turtle');

‎handlers/post.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function handler(req, res) {
2424
debug("POST -- Handling sparql-update query");
2525
return patch.handler(req, res);
2626
} else {
27-
var containerPath = file.uriToFilename(req.path, options.fileBase);
27+
var containerPath = file.uriToFilename(req.path, options.base);
2828
debug("POST -- Container path: " + containerPath);
2929
if (metadata.isMetadataFile(containerPath)) {
3030
debug("POST -- Invalid container.");
@@ -68,7 +68,7 @@ function handler(req, res) {
6868

6969
var resourceBaseUri;
7070
try {
71-
resourceBaseUri = file.filenameToBaseUri(resourcePath, options.uriBase, options.fileBase);
71+
resourceBaseUri = file.filenameToBaseUri(resourcePath, options.uri, options.base);
7272
$rdf.parse(requestText, resourceGraph,
7373
resourceBaseUri, 'text/turtle');
7474
} catch (parseErr) {

‎handlers/put.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function handler(req, res) {
1919
debug("PUT -- Text length: " + (req.text ? req.text.length : 'undefined'));
2020
res.header('MS-Author-Via' , 'SPARQL' );
2121

22-
var filename = file.uriToFilename(req.path, options.fileBase);
22+
var filename = file.uriToFilename(req.path, options.base);
2323

2424
// PUT requests not supported on containers. Use POST instead
2525
if (S(filename).endsWith('/')) {

0 commit comments

Comments
 (0)