11#!/bin/env node
22
3- var argv = require ( 'optimist' )
4- . boolean ( 'cors' )
5- . boolean ( 'v' )
6- . boolean ( 'live' )
7- . argv ;
8-
9- if ( argv . h || argv . help || argv [ '?' ] ) {
10- console . log ( [
11- "usage: ldnode [path] [options]" ,
12- "" ,
13- "options:" ,
14- " --uriBase Address, port, and default path of the server. (Example: http://localhost:3000/test/)" ,
15- " --fileBase Base location to serve resources. Requests whose paths do not have fileBase as a prefix will be ignored" ,
16- " --live Offer and support live updates" ,
17- " -p Port to use" ,
18- " -v Log messages to console" ,
19- " --changesSuffix The suffix that will be used to identify the requests that will subscribe to changes to the object requested. Defaults to ,changes" ,
20- " --cors Enable CORS via the 'Access-Control-Allow-Origin' header" ,
21- " -c Set cache time (in seconds). e.g. -c10 for 10 seconds." ,
22- " To disable caching, use -c-1." ,
23- " --changesSuffix sss Change the URI suffix used for the URI of a change stream" ,
24- " --SSESuffix sss Change the URI suffix used for the URI of a SSE stream" ,
25- "" ,
26- " -S --ssl Enable https." ,
27- " -C --cert Path to ssl cert file (default: cert.pem)." ,
28- " -K --key Path to ssl key file (default: key.pem)." ,
29- "" ,
30- " --webid Enable WebID authentication" ,
31- " --privateKey Path to the private key used to enable webid authentication" ,
32- " --cert Path to the private key used to enable webid authentication" ,
33- " -h --help Print this list and exit."
34- ] . join ( '\n' ) ) ;
35- process . exit ( ) ;
3+ var fs = require ( 'fs' ) ;
4+ var path = require ( 'path' ) ;
5+
6+ var argv = require ( 'nomnom' )
7+ . script ( 'ldnode' )
8+ . option ( 'verbose' , {
9+ abbr : 'v' ,
10+ flag : true ,
11+ help : 'Print the logs to console'
12+ } )
13+ . option ( 'version' , {
14+ flag : true ,
15+ help : 'Print current ldnode version' ,
16+ callback : function ( ) {
17+ fs . readFile ( path . resolve ( __dirname , '../package.json' ) , 'utf-8' , function ( err , file ) {
18+ console . log ( JSON . parse ( file ) . version ) ;
19+ } ) ;
20+ }
21+ } )
22+ . option ( 'uri' , {
23+ abbr : 'u' ,
24+ help : 'Default address of the server (e.g. http[s]://host:port/path)'
25+ } )
26+ . option ( 'base' , {
27+ abbr : 'b' ,
28+ full : 'base' ,
29+ help : 'Base location to serve resources'
30+ } )
31+ . option ( 'port' , {
32+ abbr : 'p' ,
33+ help : 'Port to use'
34+ } )
35+ . option ( 'cache' , {
36+ abbr : 'c' ,
37+ help : 'Set cache time (in seconds), 0 for no cache'
38+ } )
39+ . option ( 'key' , {
40+ help : 'Path to the ssl key' ,
41+ abbr : 'K' ,
42+ full : 'key'
43+ } )
44+ . option ( 'cert' , {
45+ full : 'cert' ,
46+ help : 'Path to the ssl cert' ,
47+ abbr : 'C'
48+ } )
49+ . option ( 'webid' , {
50+ help : 'Enable WebID+TLS authentication' ,
51+ full : 'webid' ,
52+ flag : true
53+ } )
54+ . option ( 'secret' , {
55+ help : 'HTTP Session secret key (e.g. "your secret phrase")' ,
56+ abbr : 's'
57+ } )
58+ . option ( 'noLive' , {
59+ full : 'no-live' ,
60+ help : 'Disable live support through WebSockets' ,
61+ abbr : 's' ,
62+ flag : true
63+ } )
64+ . parse ( ) ;
65+
66+ // Print version and leave
67+ if ( argv . version ) {
68+ return ;
3669}
3770
38- process . env . DEBUG = argv . v ? 'ldnode:*' : false ;
71+ // Set up --no-*
72+ argv . live = ! argv . noLive ;
73+
74+ // Set up debug environment
75+ process . env . DEBUG = argv . verbose ? 'ldnode:*' : false ;
3976var debug = require ( '../logging' ) . server ;
40- var ldnode = require ( '../index' ) ;
4177
42- // Signal handling
78+ // Set up port
79+ argv . port = argv . port || 3456 ;
80+
81+ // Signal handling (e.g. CTRL+C)
4382if ( process . platform !== 'win32' ) {
4483 // Signal handlers don't work on Windows.
4584 process . on ( 'SIGINT' , function ( ) {
@@ -48,9 +87,10 @@ if (process.platform !== 'win32') {
4887 } ) ;
4988}
5089
51- // Starting ldnode
90+ // Finally starting ldnode
91+ var ldnode = require ( '../index' ) ;
5292var app = ldnode . createServer ( argv ) ;
53- app . listen ( argv . p , function ( ) {
54- debug ( 'LDP started on port ' + argv . p ) ;
93+ app . listen ( argv . port , function ( ) {
94+ debug ( 'LDP started on port ' + argv . port ) ;
5595} ) ;
5696
0 commit comments