-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathcreate-server.js
More file actions
78 lines (61 loc) · 1.93 KB
/
create-server.js
File metadata and controls
78 lines (61 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
module.exports = createServer;
var express = require('express');
var fs = require('fs');
var https = require('https');
var http = require('http');
var SolidWs = require('solid-ws');
var debug = require('./debug');
var createApp = require('./create-app');
function createServer(argv) {
var app = express();
var ldpApp = createApp(argv);
var ldp = ldpApp.locals.ldp;
// Mount path
var mount = argv.mount || '/';
// Removing ending '/'
if (mount.length > 1 &&
mount[mount.length - 1] === '/') {
mount = mount.slice(0, -1);
}
app.use(mount, ldpApp);
debug.settings('mount: ' + mount);
var server = http.createServer(app);
if (ldp && (ldp.webid || argv.key || argv.cert) ) {
debug.settings("SSL Private Key path: " + argv.key);
debug.settings("SSL Certificate path: " + argv.cert);
if (!argv.cert && !argv.key) {
throw new Error("Missing SSL cert and SSL key to enable WebID");
}
if (!argv.key && argv.cert) {
throw new Error("Missing path for SSL key");
}
if (!argv.cert && argv.key) {
throw new Error("Missing path for SSL cert");
}
var key;
try {
key = fs.readFileSync(argv.key);
} catch(e) {
throw new Error("Can't find SSL key in " + argv.key);
}
var cert;
try {
cert = fs.readFileSync(argv.cert);
} catch(e) {
throw new Error("Can't find SSL cert in " + argv.cert);
}
var credentials = {
key: key,
cert: cert,
requestCert: true
};
debug.settings("Certificate: " + credentials.cert);
server = https.createServer(credentials, app);
}
// Setup Express app
if (ldp.live) {
var solidWs = SolidWs(server, ldpApp)
ldpApp.locals.ldp.live = solidWs.publish.bind(solidWs)
}
return server
}