-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathldnode.js
More file actions
158 lines (150 loc) · 4.32 KB
/
ldnode.js
File metadata and controls
158 lines (150 loc) · 4.32 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env node
var fs = require('fs')
var path = require('path')
var argv = require('nomnom')
.script('ldnode')
.option('version', {
flag: true,
help: 'Print current ldnode version',
callback: function () {
fs.readFile(path.resolve(__dirname, '../package.json'), 'utf-8', function (_, file) {
console.log(JSON.parse(file).version)
})
}
})
.option('verbose', {
abbr: 'v',
flag: true,
help: 'Print the logs to console\n'
})
.option('root', {
help: 'Root folder to serve (defaut: \'./\')'
})
.option('port', {
help: 'Port to use'
})
.option('webid', {
help: 'Enable WebID+TLS authentication',
full: 'webid',
flag: true
})
.option('key', {
help: 'Path to the SSL private key in PEM format',
full: 'ssl-key'
})
.option('cert', {
full: 'ssl-cert',
help: 'Path to the SSL certificate key in PEM format'
})
.option('idp', {
help: 'Allow users to register their WebID on subdomains\n',
full: 'allow-signup',
flag: true
})
.option('createAdmin', {
full: 'create-admin',
flag: true,
help: 'Allow a user to set up their initial identity in single-user mode'
})
.option('noLive', {
full: 'no-live',
help: 'Disable live support through WebSockets',
flag: true
})
.option('defaultApp', {
full: 'default-app',
help: 'URI to use as a default app for resources (default: https://linkeddata.github.io/warp/#/list/)'
})
.option('proxy', {
full: 'proxy',
help: 'Use a proxy on example.tld/proxyPath'
})
.option('fileBrowser', {
full: 'file-browser',
help: 'URI to use as a default app for resources (default: https://linkeddata.github.io/warp/#/list/)'
})
.option('dataBrowser', {
full: 'data-browser',
flag: true,
help: 'Enable viewing RDF resources using a default data browser application (e.g. mashlib)'
})
.option('suffixAcl', {
full: 'suffix-acl',
help: 'Suffix for acl files (default: \'.acl\')'
})
.option('suffixMeta', {
full: 'suffix-meta',
help: 'Suffix for metadata files (default: \'.meta\')'
})
.option('secret', {
help: 'Secret used to sign the session ID cookie (e.g. "your secret phrase")',
full: 'session-secret'
})
.option('noErrorPages', {
full: 'no-error-pages',
flag: true,
help: 'Disable custom error pages (use Node.js default pages instead)'
})
.option('errorPages', {
full: 'error-pages',
help: 'Folder from which to look for custom error pages files (files must be named <error-code>.html -- eg. 500.html)'
})
.option('mount', {
help: 'Serve on a specific URL path (default: \'/\')'
})
.option('forceUser', {
help: 'Force a WebID to always be logged in (useful when offline)',
full: 'force-user'
})
.parse()
function bin (argv) {
// Print version and leave
if (argv.version) {
return 0
}
// Set up --no-*
argv.live = !argv.noLive
// Set up debug environment
process.env.DEBUG = argv.verbose ? 'ldnode:*' : false
var debug = require('../lib/debug').server
// Set up port
argv.port = argv.port || 3456
// Signal handling (e.g. CTRL+C)
if (process.platform !== 'win32') {
// Signal handlers don't work on Windows.
process.on('SIGINT', function () {
debug('LDP stopped.')
process.exit()
})
}
// Finally starting ldnode
var ldnode = require('../')
var app
try {
app = ldnode.createServer(argv)
} catch (e) {
if (e.code === 'EACCES') {
console.log('You need root privileges to start on this port')
return 1
}
if (e.code === 'EADDRINUSE') {
console.log('The port ' + argv.port + ' is already in use')
return 1
}
console.log(e.message)
console.log(e.stack)
return 1
}
app.listen(argv.port, function () {
fs.readFile(path.resolve(__dirname, '../package.json'), 'utf-8', function (_, file) {
if (argv.createAdmin) {
console.log('Action required: Create your admin account on \u001b[4mhttps://localhost:' + argv.port + '/\u001b[0m')
console.log('When done, stop your server (<ctrl>+c) and restart without "--create-admin"')
} else {
console.log('Solid server (ldnode v' + JSON.parse(file).version + ') running on \u001b[4mhttps://localhost:' + argv.port + '/\u001b[0m')
console.log('Press <ctrl>+c to stop')
}
})
})
}
bin(argv)