@@ -24,6 +24,14 @@ var logging = require('./utils/logger');
24
24
25
25
var logger = logging ( "main" ) ;
26
26
27
+ var _middleware = function ( fn ) {
28
+ var __middleware ;
29
+ return function ( req , res , next ) {
30
+ if ( ! __middleware ) __middleware = fn ( ) ;
31
+ return __middleware . apply ( this , arguments ) ;
32
+ } ;
33
+ }
34
+
27
35
var prepare = function ( config ) {
28
36
return Q ( )
29
37
. then ( _ . partial ( logging . init , config ) )
@@ -134,7 +142,9 @@ var start = function(config) {
134
142
135
143
// Static files
136
144
app . use ( '/' , express . static ( path . resolve ( __dirname , '../build' ) ) ) ;
137
- app . use ( '/packages' , express . static ( path . resolve ( __dirname , '../packages' ) ) ) ;
145
+ app . use ( '/packages' , _middleware ( function ( ) {
146
+ return express . static ( config . packages . root ) ;
147
+ } ) ) ;
138
148
139
149
// Auth
140
150
app . use ( function ( req , res , next ) {
@@ -163,11 +173,9 @@ var start = function(config) {
163
173
app . use ( '/rpc' , rpc . router ) ;
164
174
165
175
// Fs direct access
166
- var _fsmiddleware ;
167
- app . use ( '/fs' , function ( req , res , next ) {
168
- if ( ! _fsmiddleware ) _fsmiddleware = express . static ( workspace . root ( ) ) ;
169
- return _fsmiddleware . apply ( this , arguments ) ;
170
- } ) ;
176
+ app . use ( '/fs' , _middleware ( function ( ) {
177
+ return express . static ( workspace . root ( ) ) ;
178
+ } ) ) ;
171
179
172
180
// Error handling
173
181
app . use ( function ( req , res , next ) {
0 commit comments