@@ -18,31 +18,31 @@ var group = require('./controllers/group');
1818var discussion = require ( './controllers/discussion' ) ;
1919var issue = require ( './controllers/issue' ) ;
2020var scriptStorage = require ( './controllers/scriptStorage' ) ;
21- var statusCodePage = require ( './libs/templateHelpers' ) . statusCodePage ;
22-
23- var modelParser = require ( './libs/modelParser' ) ;
2421
22+ var statusCodePage = require ( './libs/templateHelpers' ) . statusCodePage ;
2523var modifySessions = require ( './libs/modifySessions' ) ;
24+
2625var settings = require ( './models/settings.json' ) ;
26+
2727var connectStr = process . env . CONNECT_STRING || settings . connect ;
2828var sessionSecret = process . env . SESSION_SECRET || settings . secret ;
2929var db = mongoose . connection ;
30- var dbOptions = { server : { socketOptions : { keepAlive : 1 } } } ;
30+ var dbOptions = { server : { socketOptions : { keepAlive : 1 } } } ;
3131
3232app . set ( 'port' , process . env . PORT || 8080 ) ;
3333
3434// Connect to the database
3535mongoose . connect ( connectStr , dbOptions ) ;
3636db . on ( 'error' , console . error . bind ( console , 'connection error:' ) ) ;
37- db . once ( 'open' , function ( ) {
37+ db . once ( 'open' , function ( ) {
3838 app . listen ( app . get ( 'port' ) ) ;
3939} ) ;
4040
41- app . configure ( function ( ) {
41+ app . configure ( function ( ) {
4242 var sessionStore = new MongoStore ( { mongoose_connection : db } ) ;
4343
4444 // See https://hacks.mozilla.org/2013/01/building-a-node-js-server-that-wont-melt-a-node-js-holiday-season-part-5/
45- app . use ( function ( req , res , next ) {
45+ app . use ( function ( req , res , next ) {
4646 // check if we're toobusy
4747 if ( toobusy ( ) ) {
4848 statusCodePage ( req , res , next , {
@@ -56,13 +56,12 @@ app.configure(function(){
5656
5757 // Force HTTPS
5858 if ( app . get ( 'port' ) === 443 ) {
59- app . use ( function ( req , res , next ) {
59+ app . use ( function ( req , res , next ) {
6060 res . setHeader ( 'Strict-Transport-Security' ,
6161 'max-age=8640000; includeSubDomains' ) ;
6262
6363 if ( req . headers [ 'x-forwarded-proto' ] !== 'https' ) {
64- return res . redirect ( 301 , 'https://' + req . headers . host
65- + encodeURI ( req . url ) ) ;
64+ return res . redirect ( 301 , 'https://' + req . headers . host + encodeURI ( req . url ) ) ;
6665 }
6766
6867 next ( ) ;
@@ -96,7 +95,7 @@ app.configure(function(){
9695} ) ;
9796
9897// Build the route regex for model lists
99- function listRegex ( root , type ) {
98+ function listRegex ( root , type ) {
10099 var slash = '\/' ;
101100 if ( root === slash ) { slash = '' ; }
102101 return new RegExp ( '^' + root +
@@ -115,7 +114,7 @@ function app_route(path) {
115114 r . all = function ( cb ) {
116115 app . all . call ( app , path , cb ) ;
117116 } ;
118- methods . forEach ( function ( method ) {
117+ methods . forEach ( function ( method ) {
119118 r [ method ] = function ( cb ) {
120119 app [ method ] . call ( app , path , cb ) ;
121120 return r ;
@@ -153,7 +152,6 @@ app_route('/user/add/lib/new').get(script.lib(user.editScript)).post(script.lib(
153152app_route ( '/user/add/scripts/upload' ) . post ( user . uploadScript ) ;
154153app_route ( '/user/add/lib/upload' ) . post ( script . lib ( user . uploadScript ) ) ;
155154
156-
157155// Script routes
158156app_route ( '/scripts/:username/:namespace?/:scriptname' ) . get ( script . view ) ;
159157app_route ( '/script/:username/:namespace?/:scriptname/edit' ) . get ( script . edit ) . post ( script . edit ) ;
@@ -165,7 +163,7 @@ app.get('/install/:username/:namespace?/:scriptname', scriptStorage.sendScript);
165163app . get ( '/meta/:username/:namespace?/:scriptname' , scriptStorage . sendMeta ) ;
166164app . get ( '/vote/scripts/:username/:namespace?/:scriptname/:vote' , script . vote ) ;
167165app . post ( '/github/hook' , scriptStorage . webhook ) ;
168- app . post ( '/github/service' , function ( req , res , next ) { next ( ) ; } ) ;
166+ app . post ( '/github/service' , function ( req , res , next ) { next ( ) ; } ) ;
169167
170168// Library routes
171169app . get ( listRegex ( '\/toolbox' , 'lib' ) , main . toolbox ) ;
@@ -180,7 +178,7 @@ app.get('/vote/libs/:username/:scriptname/:vote', script.lib(script.vote));
180178
181179// Issues routes
182180app_route ( '/:type(scripts|libs)/:username/:namespace?/:scriptname/issues/:open(closed)?' ) . get ( issue . list ) ;
183- // app_route('/:type(scripts|libs)/:username/:namespace?/:scriptname/issues/:topic').get(issue.view);
181+ //app_route('/:type(scripts|libs)/:username/:namespace?/:scriptname/issues/:topic').get(issue.view);
184182app_route ( '/:type(scripts|libs)/:username/:namespace?/:scriptname/issue/new' ) . get ( issue . open ) . post ( issue . open ) ;
185183app_route ( '/:type(scripts|libs)/:username/:namespace?/:scriptname/issues/:topic' ) . get ( issue . view ) ;
186184
@@ -201,9 +199,8 @@ app_route('/mod/removed').get(moderation.removedItemListPage);
201199app_route ( '/mod/removed/:id' ) . get ( moderation . removedItemPage ) ;
202200app . get ( '/flag/users/:username/:unflag?' , user . flag ) ;
203201app . get ( '/flag/scripts/:username/:namespace?/:scriptname/:unflag?' , script . flag ) ;
204- app . get ( '/flag/libs/:username/:scriptname/:unflag?' , script . lib ( script . flag ) ) ; //
205- app . get ( listRegex ( '\/flagged(?:\/([^\/]+?))?' , 'user|script' ) ,
206- moderation . flagged ) ; //
202+ app . get ( '/flag/libs/:username/:scriptname/:unflag?' , script . lib ( script . flag ) ) ;
203+ app . get ( listRegex ( '\/flagged(?:\/([^\/]+?))?' , 'user|script' ) , moderation . flagged ) ;
207204app . get ( listRegex ( '\/graveyard(?:\/([^\/]+?))?' , '' ) , moderation . graveyard ) ;
208205app . get ( / ^ \/ r e m o v e \/ ( .+ ?) \/ ( .+ ) $ / , remove . rm ) ;
209206
@@ -237,10 +234,9 @@ app.get(listRegex('\/', 'script'), main.home);
237234
238235// Fallback routes
239236app . use ( express . static ( __dirname + '/public' ) ) ;
240- app . use ( function ( req , res , next ) {
237+ app . use ( function ( req , res , next ) {
241238 statusCodePage ( req , res , next , {
242239 statusCode : 404 ,
243240 statusMessage : 'This is not the page you\'re are looking for.' ,
244241 } ) ;
245242} ) ;
246-
0 commit comments