Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bin/ldnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ if (process.platform !== 'win32') {

// Finally starting ldnode
var ldnode = require('../index');
var app = ldnode.createServer(argv);
var app;
try {
app = ldnode.createServer(argv);
} catch(e) {
console.log(e.message);
return 1;
}
app.listen(argv.port, function() {
debug('LDP started on port ' + argv.port);
});
Expand Down
36 changes: 32 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,39 @@ function createServer(argv) {
if (opts && (opts.webid || opts.key || opts.cert) ) {
debug("SSL Private Key path: " + opts.key);
debug("SSL Certificate path: " + opts.cert);

if (!opts.cert && !opts.key) {
throw new Error("Missing SSL cert and SSL key to enable WebID");
}

if (!opts.key && opts.cert) {
throw new Error("Missing path for SSL key");
}

if (!opts.cert && opts.key) {
throw new Error("Missing path for SSL cert");
}

var key;
try {
key = fs.readFileSync(opts.key);
} catch(e) {
throw new Error("Can't find SSL key in " + opts.key);
}

var cert;
try {
cert = fs.readFileSync(opts.cert);
} catch(e) {
throw new Error("Can't find SSL cert in " + opts.cert);
}

var credentials = {
key: fs.readFileSync(opts.key),
cert: fs.readFileSync(opts.cert),
requestCert: true
};
key: key,
cert: cert,
requestCert: true
};

debug("Private Key: " + credentials.key);
debug("Certificate: " + credentials.cert);

Expand Down