Skip to content

Commit 007482d

Browse files
committed
applying standard
1 parent 2856432 commit 007482d

19 files changed

Lines changed: 1825 additions & 1900 deletions

bin/ldnode.js

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

3-
var fs = require('fs');
4-
var path = require('path');
3+
var fs = require('fs')
4+
var path = require('path')
55
var argv = require('nomnom')
66
.script('ldnode')
77
.option('verbose', {
@@ -13,14 +13,14 @@ var argv = require('nomnom')
1313
flag: true,
1414
help: 'Print current ldnode version',
1515
callback: function () {
16-
fs.readFile(path.resolve(__dirname, '../package.json'), 'utf-8', function(err, file) {
17-
console.log(JSON.parse(file).version);
18-
});
16+
fs.readFile(path.resolve(__dirname, '../package.json'), 'utf-8', function (_, file) {
17+
console.log(JSON.parse(file).version)
18+
})
1919
}
2020
})
2121
.option('mount', {
2222
abbr: 'm',
23-
help: 'Relative URL from which to serve the Linked Data Platform (default: \'/\')'
23+
help: "Relative URL from which to serve the Linked Data Platform (default: '/')"
2424
})
2525
.option('root', {
2626
abbr: 'r',
@@ -76,12 +76,12 @@ var argv = require('nomnom')
7676
})
7777
.option('suffixAcl', {
7878
full: 'suffix-acl',
79-
help: 'Suffix for acl files (default: \'.acl\')',
79+
help: "Suffix for acl files (default: '.acl')",
8080
abbr: 'sA'
8181
})
8282
.option('suffixMeta', {
8383
full: 'suffix-meta',
84-
help: 'Suffix for metadata files (default: \'.meta\')',
84+
help: "Suffix for metadata files (default: '.meta')",
8585
abbr: 'sM'
8686
})
8787
.option('noErrorPages', {
@@ -97,42 +97,46 @@ var argv = require('nomnom')
9797
full: 'default-app',
9898
help: 'URI to use as a default app for resources (default: https://linkeddata.github.io/warp/#/list/)'
9999
})
100-
.parse();
100+
.parse()
101101

102-
// Print version and leave
103-
if (argv.version) {
104-
return;
105-
}
102+
function bin (argv) {
103+
// Print version and leave
104+
if (argv.version) {
105+
return 0
106+
}
106107

107-
// Set up --no-*
108-
argv.live = !argv.noLive;
108+
// Set up --no-*
109+
argv.live = !argv.noLive
109110

110-
// Set up debug environment
111-
process.env.DEBUG = argv.verbose ? 'ldnode:*' : false;
112-
var debug = require('../lib/debug').server;
111+
// Set up debug environment
112+
process.env.DEBUG = argv.verbose ? 'ldnode:*' : false
113+
var debug = require('../lib/debug').server
113114

114-
// Set up port
115-
argv.port = argv.port || 3456;
115+
// Set up port
116+
argv.port = argv.port || 3456
116117

117-
// Signal handling (e.g. CTRL+C)
118-
if (process.platform !== 'win32') {
118+
// Signal handling (e.g. CTRL+C)
119+
if (process.platform !== 'win32') {
119120
// Signal handlers don't work on Windows.
120-
process.on('SIGINT', function() {
121-
debug("LDP stopped.");
122-
process.exit();
123-
});
124-
}
121+
process.on('SIGINT', function () {
122+
debug('LDP stopped.')
123+
process.exit()
124+
})
125+
}
125126

126-
// Finally starting ldnode
127-
var ldnode = require('../');
128-
var app;
129-
try {
130-
app = ldnode.createServer(argv);
131-
} catch(e) {
132-
console.log(e.message);
133-
console.log(e.stack)
134-
return 1;
127+
// Finally starting ldnode
128+
var ldnode = require('../')
129+
var app
130+
try {
131+
app = ldnode.createServer(argv)
132+
} catch(e) {
133+
console.log(e.message)
134+
console.log(e.stack)
135+
return 1
136+
}
137+
app.listen(argv.port, function () {
138+
debug('LDP started on port ' + argv.port)
139+
})
135140
}
136-
app.listen(argv.port, function() {
137-
debug('LDP started on port ' + argv.port);
138-
});
141+
142+
bin(argv)

examples/custom-error-handling.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
var ldnode = require('../'); // or require('ldnode')
2-
var path = require('path');
1+
var ldnode = require('../')
2+
var path = require('path')
33

44
ldnode
55
.createServer({
66
webid: true,
77
cert: path.resolve('./test/keys/cert.pem'),
88
key: path.resolve('./test/keys/key.pem'),
9-
errorHandler: function(err, req, res, next) {
9+
errorHandler: function (err, req, res, next) {
1010
if (err.status !== 200) {
11-
console.log('Oh no! There is an error:' + err.message);
12-
res.status(err.status);
11+
console.log('Oh no! There is an error:' + err.message)
12+
res.status(err.status)
1313

1414
// Now you can send the error how you want
1515
// Maybe you want to render an error page
@@ -20,14 +20,13 @@ ldnode
2020
// Or you want to respond in JSON?
2121

2222
res.json({
23-
title: err.status + ": This is an error!",
23+
title: err.status + ': This is an error!',
2424
message: err.message
25-
});
25+
})
2626
}
2727

2828
}
2929
})
30-
.listen(3456, function() {
31-
console.log('started ldp with webid on port ' + 3456);
32-
});
33-
30+
.listen(3456, function () {
31+
console.log('started ldp with webid on port ' + 3456)
32+
})

examples/ldp-with-webid.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ ldnode
77
cert: path.resolve('../test/keys/cert.pem'),
88
key: path.resolve('../test/keys/key.pem')
99
})
10-
.listen(3456, function() {
10+
.listen(3456, function () {
1111
console.log('started ldp with webid on port ' + 3456)
1212
})
13-

examples/simple-express-app.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@ app.use('/ldp', ldp)
1818
app.listen(3000, function () {
1919
console.log('Server started on port 3000!')
2020
})
21-

examples/simple-ldp-server.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ var ldnode = require('../') // or require('ldnode')
22

33
// Startin ldnode server
44
var ldp = ldnode.createServer()
5-
ldp.listen(3456, function() {
5+
ldp.listen(3456, function () {
66
console.log('Starting server on port ' + 3456)
77
console.log('LDP will run on /')
88
})
9-

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
module.exports = require('./lib/create-app');
2-
module.exports.createServer = require('./lib/create-server');
1+
module.exports = require('./lib/create-app')
2+
module.exports.createServer = require('./lib/create-server')

lib/acl.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ function getUserId (req, callback) {
291291

292292
var delegator = rdfVocab.debrack(onBehalfOf)
293293
verifyDelegator(req.hostname, delegator, req.session.userId, function (err, res) {
294+
295+
if (err) {
296+
err.status = 500
297+
return callback(err)
298+
}
299+
294300
if (res) {
295301
debug('Request User ID (delegation) :' + delegator)
296302
return callback(null, delegator)
@@ -303,6 +309,10 @@ function verifyDelegator (host, ldp, baseUri, delegator, delegatee, callback) {
303309
fetchDocument(host, ldp, baseUri)(delegator, function (err, delegatorGraph) {
304310

305311
// TODO handle error
312+
if (err) {
313+
err.status = 500
314+
return callback(err)
315+
}
306316

307317
var delegatesStatements = delegatorGraph
308318
.each(delegatorGraph.sym(delegator),

lib/ldp.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ LDP.prototype.listContainer = function (filename, uri, containerData, contentTyp
292292
}
293293
],
294294
function (err, data) {
295-
// if (err) {
296-
// return callback(error(500, err.message))
297-
// }
295+
if (err) {
296+
return callback(error(500, err.message))
297+
}
298298
var turtleData
299299
try {
300300
turtleData = $rdf.serialize(

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@
6262
"chai": "^3.0.0",
6363
"mocha": "^2.2.5",
6464
"nock": "^2.10.0",
65+
"standard": "^5.4.1",
6566
"supertest": "^1.0.1"
6667
},
6768
"main": "index.js",
6869
"scripts": {
6970
"start": "node ./bin/ldnode.js",
70-
"test": "./node_modules/mocha/bin/mocha ./test/*.js",
71+
"standard": "standard --global it --global describe --global after --global beforeEach --global before",
72+
"mocha": "./node_modules/mocha/bin/mocha ./test/*.js",
73+
"test": "npm run standard && npm run mocha",
7174
"test-debug": "DEBUG='ldnode:*' ./node_modules/mocha/bin/mocha ./test/*.js",
7275
"test-acl": "./node_modules/mocha/bin/mocha ./test/acl.js",
7376
"test-params": "./node_modules/mocha/bin/mocha ./test/params.js",

0 commit comments

Comments
 (0)