2013-11-18 02:39:08 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var  path  =  require ( 'path' ) ,  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									fs  =  require ( 'fs' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-04 18:05:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									nconf  =  require ( 'nconf' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-18 02:39:08 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									express  =  require ( 'express' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-10 16:22:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									express _namespace  =  require ( 'express-namespace' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-22 15:17:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									WebServer  =  express ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-04 18:05:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									server , 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-30 16:28:22 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									winston  =  require ( 'winston' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-04 01:46:50 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									validator  =  require ( 'validator' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-14 16:41:34 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									async  =  require ( 'async' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-18 02:39:08 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									utils  =  require ( '../public/src/utils' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-01 17:26:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									templates  =  require ( './../public/src/templates' ) ,  // todo remove
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									translator  =  require ( './../public/src/translator' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 17:10:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									db  =  require ( './database' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-18 02:39:08 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									user  =  require ( './user' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									notifications  =  require ( './notifications' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									auth  =  require ( './routes/authentication' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									meta  =  require ( './meta' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									plugins  =  require ( './plugins' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-25 16:39:27 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									logger  =  require ( './logger' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-01 17:26:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									middleware  =  require ( './middleware' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-01 17:35:47 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									routes  =  require ( './routes' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-25 14:13:09 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									admin  =  require ( './routes/admin' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									apiRoute  =  require ( './routes/api' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									feedsRoute  =  require ( './routes/feeds' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-25 16:50:58 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									metaRoute  =  require ( './routes/meta' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-02 15:57:43 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-04 18:05:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								if ( nconf . get ( 'ssl' ) )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									server  =  require ( 'https' ) . createServer ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										key :  fs . readFileSync ( nconf . get ( 'ssl' ) . key ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-04 18:09:43 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										cert :  fs . readFileSync ( nconf . get ( 'ssl' ) . cert ) 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-04 18:05:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ,  WebServer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  else  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									server  =  require ( 'http' ) . createServer ( WebServer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								( function  ( app )  {  
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"use strict" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-02 14:21:24 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var 	clientScripts , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										port  =  nconf . get ( 'PORT' )  ||  nconf . get ( 'port' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-25 16:28:07 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-11-25 12:35:54 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									plugins . ready ( function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Minify client-side libraries
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										meta . js . get ( function  ( err ,  scripts )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											clientScripts  =  scripts . map ( function  ( script )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												script  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													script :  script 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  script ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-24 12:33:51 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-23 13:14:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-01 17:26:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									logger . init ( app ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-01 17:35:47 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									auth . registerApp ( app ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-02 13:56:46 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-01 17:26:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									async . series ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										themesData :  meta . themes . get , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										currentThemeData :  function ( next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											db . getObjectFields ( 'config' ,  [ 'theme:type' ,  'theme:id' ,  'theme:staticDir' ,  'theme:templates' ] ,  next ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ,  function ( err ,  data )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-02 14:16:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										middleware  =  middleware ( app ,  data ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										routes ( app ,  middleware ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-01 17:26:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											winston . error ( 'Errors were encountered while attempting to initialise NodeBB.' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											process . exit ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( process . env . NODE _ENV  ===  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												winston . info ( 'Middlewares loaded.' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-22 16:51:32 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-11-28 17:37:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Cache static files on production
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( global . env  !==  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										app . enable ( 'cache' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-04 20:37:13 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										app . enable ( 'minification' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-09 14:50:40 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-10 22:20:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Configure cache-buster timestamp
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										require ( 'child_process' ) . exec ( 'git describe --tags' ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											cwd :  path . join ( _ _dirname ,  '../' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ,  function ( err ,  stdOut )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( ! err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												meta . config [ 'cache-buster' ]  =  stdOut . trim ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-13 12:26:43 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												fs . stat ( path . join ( _ _dirname ,  '../package.json' ) ,  function ( err ,  stats )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													meta . config [ 'cache-buster' ]  =  new  Date ( stats . mtime ) . getTime ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-09 14:50:40 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-10 22:20:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-09 14:50:40 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-02 14:21:24 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( port  !=  80  &&  port  !=  443  &&  nconf . get ( 'use_port' )  ===  false )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-01 17:26:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										winston . info ( 'Enabling \'trust proxy\'' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										app . enable ( 'trust proxy' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-29 20:27:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-02 14:21:24 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ( port  ==  80  ||  port  ==  443 )  &&  process . env . NODE _ENV  !==  'development' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-01 17:26:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										winston . info ( 'Using ports 80 and 443 is not recommend; use a proxy instead. See README.md' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-13 11:10:17 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-01 17:26:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									module . exports . server  =  server ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									module . exports . init  =  function  ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-23 17:08:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										plugins . fireHook ( 'action:app.load' ,  app ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-22 11:42:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 23:07:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										server . on ( "error" ,  function ( e ) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( e . code  ===  'EADDRINUSE' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												winston . error ( 'NodeBB address in use, exiting...' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												process . exit ( 1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												throw  e ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										winston . info ( 'NodeBB attempting to listen on: '  +  ( ( nconf . get ( 'bind_address' )  ===  "0.0.0.0"  ||  ! nconf . get ( 'bind_address' ) )  ?  '0.0.0.0'  :  nconf . get ( 'bind_address' ) )  +  ':'  +  port ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										server . listen ( port ,  nconf . get ( 'bind_address' ) ,  function ( ) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											winston . info ( 'NodeBB Ready' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-17 13:36:35 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									app . create _route  =  function  ( url ,  tpl )  {  // to remove
 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-24 10:00:57 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										var 	routerScript  =  ' < script >  \ 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-24 10:09:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												ajaxify . initialLoad  =  true ;  \ 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-24 10:00:57 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												templates . ready ( function ( ) { ajaxify . go ( "' + url + '" ,  null ,  true ) ; } ) ;  \ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											< / s c r i p t > ' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  routerScript ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-09 06:26:32 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-22 16:51:32 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								} ( WebServer ) ) ;