Skip to content

Commit 0487c15

Browse files
committed
No more uribase
1 parent 3b95bda commit 0487c15

10 files changed

Lines changed: 26 additions & 43 deletions

File tree

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ npm install
3030
```javascript
3131
var ldnode = require('ldnode')
3232

33-
var ldp = ldnode.createServer({
34-
uri: "http://example.com/test/",
35-
base: __dirname + '/test/'
36-
})
33+
var ldp = ldnode.createServer()
3734
ldp.listen(1234, function() {
3835
// Started Linked Data Platform
3936
})
@@ -46,7 +43,7 @@ You can integrate it with your existing express app
4643
```javascript
4744
var ldnode = require('ldnode')
4845
var app = require('express')()
49-
app.use('/test', ldnode(opts))
46+
app.use('/test', ldnode())
5047
...
5148
```
5249

@@ -76,18 +73,19 @@ Usage: ldnode [options]
7673
Options:
7774
-v, --verbose Print the logs to console
7875
--version Print current ldnode version
79-
-u, --uri Default address of the server (e.g. http[s]://host:port/path)
76+
-m, --mount Where to mount Linked Data Platform (default: '/')
8077
-b, --base Base location to serve resources
8178
-p, --port Port to use
8279
-c, --cache Set cache time (in seconds), 0 for no cache
8380
-K, --key Path to the ssl key
8481
-C, --cert Path to the ssl cert
8582
--webid Enable WebID+TLS authentication
8683
-s, --secret HTTP Session secret key (e.g. "your secret phrase")
87-
--no-live Disable live support through WebSockets
84+
--no-live Disable live support through WebSockets
8885
-sA, --suffix-acl Suffix for acl files (default: '.acl')
8986
-sC, --suffix-changes Suffix for acl files (default: '.changes')
9087
-sE, --suffix-sse Suffix for SSE files (default: '.events')
88+
9189
```
9290

9391
## Tests

acl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function allow(mode, req, res) {
3535
for (var i = 0; i < depth.length; i++) {
3636
var pathAcl = S(filepath).endsWith(options.suffixAcl) ?
3737
filepath : filepath + options.suffixAcl;
38-
var uri = options.uri || file.uriAbs(req);
38+
var uri = file.uriAbs(req);
3939
var pathUri = file.filenameToBaseUri(filepath, uri, options.base);
4040
relativePath = path.relative(options.base, filepath);
4141

bin/ldnode.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ var argv = require('nomnom')
1919
});
2020
}
2121
})
22-
.option('uri', {
23-
abbr: 'u',
24-
help: 'Default address of the server (e.g. http[s]://host:port/path)'
22+
.option('mount', {
23+
abbr: 'm',
24+
help: 'Where to mount Linked Data Platform (default: \'/\')'
2525
})
2626
.option('base', {
2727
abbr: 'b',

fileStore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function uriToRelativeFilename(uri, base) {
2727

2828
function filenameToBaseUri(filename, uri, base) {
2929
var uriPath = S(filename).strip(base).toString();
30-
return uri + uriPath;
30+
return uri + '/' + uriPath;
3131
}
3232

3333
function uriBase(req) {

handlers/get.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var metaExtension = '.meta';
2222

2323
function get(req, res, includeBody) {
2424
var options = req.app.locals.ldp;
25-
var uri = options.uri || file.uriAbs(req);
25+
var uri = file.uriAbs(req);
2626

2727
// Add request to subscription service
2828
if (('' + req.path).slice(-options.suffixChanges.length) ===

handlers/post.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,13 @@ function handler(req, res) {
7777
// Get the request text
7878
// TODO make sure correct text is selected
7979
var requestText = req.convertedText || req.text;
80-
var uri = options.uri || file.uriAbs(req);
80+
var uri = file.uriAbs(req);
8181
var resourceBaseUri = file.filenameToBaseUri(
8282
resourcePath,
8383
uri,
8484
options.base);
8585

8686
try {
87-
console.log(requestText);
8887
$rdf.parse(
8988
requestText,
9089
resourceGraph,

index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ function ldnode (argv) {
4848
}));
4949

5050
// Creating root container
51-
// TODO make sure pathStart is where it is mounted
52-
container.createRootContainer(opts.fileBase, opts.pathStart);
51+
container.createRootContainer(opts.fileBase, opts.mount);
5352

5453
// Setting up routes
55-
app.use(opts.pathStart, routes());
54+
app.use('/', routes());
5655

5756
// Adding proxy
5857
if (opts.xssProxy) {
@@ -65,14 +64,16 @@ function ldnode (argv) {
6564
ws(app);
6665
}
6766

68-
debugServer("Router attached to " + opts.pathStart);
67+
debugServer("Router attached to " + opts.mount);
6968

7069
return app;
7170
}
7271

7372
function createServer(argv) {
74-
var app = ldnode(argv);
75-
var opts = app.locals.ldp;
73+
var app = express();
74+
var ldp = ldnode(argv);
75+
var opts = ldp.locals.ldp;
76+
app.use(opts.mount, ldp);
7677

7778
if (opts && (opts.webid || opts.key || opts.cert) ) {
7879
debug("SSL Private Key path: " + opts.key);

options.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ function params(argv) {
2020
opts.secret = argv.secret;
2121
opts.cert = argv.cert;
2222
opts.key = argv.key;
23-
// TODO no need of uri
24-
opts.uri = opts.uri = argv.uri || argv.uriBase;
23+
opts.mount = argv.mount || '/';
2524
opts.verbose = argv.verbose;
2625
opts.webid = argv.webid;
2726

@@ -35,32 +34,19 @@ function params(argv) {
3534
opts.base += '/';
3635
}
3736

38-
opts.pathStart = '/' +
39-
opts.uri
40-
.split('//')[1]
41-
.split('/')
42-
.slice(1)
43-
.join('/');
44-
45-
opts.prePathSlash = opts.uri
46-
.split('/')
47-
.slice(0, 3)
48-
.join('/');
49-
50-
opts.pathFilter = regexp().start(opts.pathStart).toRegExp();
37+
opts.pathFilter = regexp().start(opts.mount).toRegExp();
5138
opts.xssProxy = argv.xssProxy;
5239
opts.proxyFilter = regexp().start(opts.xssProxy).toRegExp();
5340

5441
// TODO this should be an attribute of an object
5542
opts.usedURIs = {};
5643

57-
debug("uri: " + opts.uri);
58-
debug("pathStart: " + opts.pathStart);
44+
debug("mount: " + opts.mount);
5945
debug("URI path filter regexp: " + opts.pathFilter);
6046
debug("Verbose: " + !!opts.verbose);
6147
debug("WebID: " + !!opts.webid);
6248
debug("Live: " + !!opts.live);
6349

64-
return opts
50+
return opts;
6551
}
6652

test/secure-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('ACL', function() {
1515
var address = 'https://localhost:3456/test/';
1616

1717
var ldp = ldnode.createServer({
18-
uri: address,
18+
mount: '/test',
1919
base: __dirname,
2020
key: __dirname + '/key.pem',
2121
cert: __dirname + '/cert.pem',

test/test.js

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

88
describe('ldnode', function() {
9-
var address = 'http://localhost:3457/test/';
9+
var address = 'http://localhost:3457';
1010
var ldp = ldnode.createServer({
11-
uri: address,
1211
base: __dirname
1312
});
1413
ldp.listen(3457);
@@ -156,7 +155,7 @@ describe('ldnode', function() {
156155
.send(postRequest1Body)
157156
.set('content-type', 'text/turtle')
158157
.set('slug', 'post-resource-1')
159-
.expect('location', address + 'post-resource-1.ttl')
158+
.expect('location', address + '/post-resource-1.ttl')
160159
.expect(201, done);
161160
});
162161
it('Should reject requests to existing resources', function(done) {

0 commit comments

Comments
 (0)