@@ -16,7 +16,11 @@ var passport = require('passport');
1616var Models = require ( './models' ) ;
1717var User = Models . User ;
1818var GitHubStrategy = require ( 'passport-github' ) . Strategy ;
19- var githubStrategyMiddleware = require ( './midderwares/github_strategy' ) ;
19+ var githubStrategyMiddleware = require ( './middlewares/github_strategy' ) ;
20+ var routes = require ( './routes' ) ;
21+
22+ var maxAge = 3600000 * 24 * 30 ;
23+ var staticDir = path . join ( __dirname , 'public' ) ;
2024
2125// assets
2226var assets = { } ;
@@ -32,7 +36,6 @@ if (config.mini_assets) {
3236// host: http://127.0.0.1
3337var urlinfo = require ( 'url' ) . parse ( config . host ) ;
3438config . hostname = urlinfo . hostname || config . host ;
35- var routes = require ( './routes' ) ;
3639
3740config . upload_dir = config . upload_dir || path . join ( __dirname , 'public' , 'user_data' , 'images' ) ;
3841// ensure upload dir exists
@@ -59,25 +62,30 @@ app.configure(function () {
5962 app . use ( passport . initialize ( ) ) ;
6063 // custom middleware
6164 app . use ( require ( './controllers/sign' ) . auth_user ) ;
65+ app . use ( '/upload/' , express . static ( config . upload_dir , { maxAge : maxAge } ) ) ;
66+ // old image url: http://host/user_data/images/xxxx
67+ app . use ( '/user_data/' , express . static ( path . join ( __dirname , 'public' , 'user_data' ) , { maxAge : maxAge } ) ) ;
68+ } ) ;
6269
63- var csrf = express . csrf ( ) ;
70+ app . configure ( 'development' , function ( ) {
71+ app . use ( '/public' , express . static ( staticDir ) ) ;
72+ app . use ( express . errorHandler ( { dumpExceptions : true , showStack : true } ) ) ;
73+ } ) ;
74+
75+ app . configure ( 'production' , function ( ) {
6476 app . use ( function ( req , res , next ) {
77+ var csrf = express . csrf ( ) ;
6578 // ignore upload image
6679 if ( req . body && req . body . user_action === 'upload_image' ) {
6780 return next ( ) ;
6881 }
6982 csrf ( req , res , next ) ;
7083 } ) ;
84+ app . use ( '/public' , express . static ( staticDir , { maxAge : maxAge } ) ) ;
85+ app . use ( express . errorHandler ( ) ) ;
86+ app . set ( 'view cache' , true ) ;
7187} ) ;
7288
73- if ( process . env . NODE_ENV !== 'test' ) {
74- // plugins
75- var plugins = config . plugins || [ ] ;
76- for ( var i = 0 , l = plugins . length ; i < l ; i ++ ) {
77- var p = plugins [ i ] ;
78- app . use ( require ( './plugins/' + p . name ) ( p . options ) ) ;
79- }
80- }
8189
8290// set static, dynamic helpers
8391app . helpers ( {
@@ -87,23 +95,14 @@ app.helpers({
8795} ) ;
8896app . dynamicHelpers ( require ( './common/render_helpers' ) ) ;
8997
90- var maxAge = 3600000 * 24 * 30 ;
91- app . use ( '/upload/' , express . static ( config . upload_dir , { maxAge : maxAge } ) ) ;
92- // old image url: http://host/user_data/images/xxxx
93- app . use ( '/user_data/' , express . static ( path . join ( __dirname , 'public' , 'user_data' ) , { maxAge : maxAge } ) ) ;
94-
95- var staticDir = path . join ( __dirname , 'public' ) ;
96- app . configure ( 'development' , function ( ) {
97- app . use ( '/public' , express . static ( staticDir ) ) ;
98- app . use ( express . errorHandler ( { dumpExceptions : true , showStack : true } ) ) ;
99- } ) ;
100-
101- app . configure ( 'production' , function ( ) {
102- app . use ( '/public' , express . static ( staticDir , { maxAge : maxAge } ) ) ;
103- app . use ( express . errorHandler ( ) ) ;
104- app . set ( 'view cache' , true ) ;
105- } ) ;
106-
98+ if ( process . env . NODE_ENV !== 'test' ) {
99+ // plugins
100+ var plugins = config . plugins || [ ] ;
101+ for ( var i = 0 , l = plugins . length ; i < l ; i ++ ) {
102+ var p = plugins [ i ] ;
103+ app . use ( require ( './plugins/' + p . name ) ( p . options ) ) ;
104+ }
105+ }
107106
108107// github oauth
109108passport . serializeUser ( function ( user , done ) {
@@ -114,7 +113,6 @@ passport.deserializeUser(function (user, done) {
114113} ) ;
115114passport . use ( new GitHubStrategy ( config . GITHUB_OAUTH , githubStrategyMiddleware ) ) ;
116115
117-
118116// routes
119117routes ( app ) ;
120118
0 commit comments