@@ -28,9 +28,11 @@ global.opts = loadOptions();
2828// Arguments parse */
2929commander
3030 . option ( '-l, --log [string]' , 'Log level (default: ' + global . opts . core . common . defaultLogLevel + ').' , global . opts . core . common . defaultLogLevel )
31- . option ( '-p, --port [number]' , 'Server port (default: ' + global . opts . core . common . port + ').' , global . opts . core . common . port )
31+ . option ( '-p, --port [number]' , 'Server port (default: ' + global . opts . core . server . port + ').' )
32+ . option ( '--hostname [string]' , 'Server hostname (default: ' + global . opts . core . server . hostname + ').' )
3233 . option ( '--html' , 'Turn on HTML parser on app start (requires installed and enabled parser).' )
3334 . option ( '--test' , 'Run app with tests.' )
35+ . option ( '--no-watch' , 'Run with disabled watcher.' )
3436 . parse ( process . argv ) ;
3537
3638global . commander = commander ;
@@ -48,8 +50,13 @@ var logger = require('./core/logger');
4850var log = logger . log ;
4951global . log = log ;
5052
51- if ( commander . html ) global . opts . core . parseHTML . onStart = true ;
52- if ( commander . port ) global . opts . core . common . port = parseInt ( commander . port ) ;
53+ if ( commander . html ) {
54+ global . opts . plugins . htmlParser . enabled = true ;
55+ global . opts . plugins . htmlParser . onStart = true ;
56+ }
57+ if ( commander . port ) global . opts . core . server . port = parseInt ( commander . port ) ;
58+ if ( commander . hostname ) global . opts . core . server . hostname = commander . hostname ;
59+ if ( ! commander . watch ) global . opts . core . watch . enabled = false ;
5360/* /Globals */
5461
5562
@@ -97,14 +104,15 @@ app.use(bodyParser.json());
97104
98105
99106
100- /* Middlewares */
107+ /* Includes */
108+
109+ // Middlewares
110+ require ( './core/middlewares/loader' ) . process ( app , global . opts ) ;
101111
102112// Auth initializing
103113var auth = require ( './core/auth' ) ( app ) ;
104114app . use ( auth . everyauth . middleware ( ) ) ;
105115
106- // Clarify
107- app . use ( require ( './core/middleware/clarify' ) ) ;
108116
109117// File tree module
110118var fileTree = require ( './core/file-tree' ) ;
@@ -133,29 +141,6 @@ app.use('/api/updateFileTree', function(req, res){
133141} ) ;
134142
135143
136- // Middleware that loads spec content
137- var read = require ( "./core/middleware/read" ) ;
138- app . use ( read . process ) ;
139-
140- // Markdown
141- app . use ( require ( "./core/middleware/md" ) . process ) ;
142- app . use ( require ( "./core/middleware/mdTag" ) . process ) ;
143-
144- // Load user defined middleware, that processes spec content
145- require ( "./core/middleware/userMiddleware" ) ;
146-
147- // Middleware that wraps spec with Source template
148- app . use ( require ( "./core/middleware/wrap" ) . process ) ;
149-
150- // Middleware that sends final spec response
151- app . use ( require ( "./core/middleware/send" ) . process ) ;
152-
153- /* /Middlewares */
154-
155-
156-
157- /* Includes */
158-
159144// Routes
160145require ( './core/routes' ) ;
161146
@@ -194,15 +179,18 @@ app.use(express.static(app.get('user')));
194179
195180// Page 404
196181app . use ( function ( req , res ) {
197-
198182 if ( req . accepts ( 'html' ) ) {
183+ if ( req . url === '/' ) {
184+ res . redirect ( '/docs' ) ;
185+ return ;
186+ }
187+
199188 var headerFooterHTML = headerFooter . getHeaderAndFooter ( ) ;
200189 res . status ( 404 ) . render ( path . join ( __dirname , '/core/views/404.ejs' ) , {
201190 header : headerFooterHTML . header ,
202191 footer : headerFooterHTML . footer
203192 } ) ;
204193 }
205-
206194} ) ;
207195/* /Serving content */
208196
@@ -231,14 +219,13 @@ app.use(logErrors);
231219
232220
233221
234- // Server start
222+ /* Server start */
235223if ( ! module . parent ) {
236- var port = global . opts . core . common . port ;
237-
238- app . listen ( port ) ;
239- var portString = port . toString ( ) ;
224+ var serverOpts = global . opts . core . server ;
225+ var port = serverOpts . port ;
240226
241- log . info ( '[SOURCEJS] launched on http://127.0.0.1:' . blue + portString . red + ' in ' . blue + MODE . blue + ' mode...' . blue ) ;
227+ app . listen ( port , serverOpts . hostname , serverOpts . backlog , serverOpts . callback ) ;
228+ log . info ( '[SOURCEJS] launched on http://127.0.0.1:' . blue + ( port . toString ( ) ) . red + ' in ' . blue + MODE . blue + ' mode...' . blue ) ;
242229
243230 if ( commander . test ) {
244231 var spawn = require ( 'cross-spawn' ) ;
@@ -255,3 +242,4 @@ if (!module.parent) {
255242 } ) ;
256243 }
257244}
245+ /* Server start */
0 commit comments