@@ -262,6 +262,18 @@ class Web {
262262 app . use ( i18n . redirect ) ;
263263 }
264264
265+ app . use ( ( ctx , next ) => {
266+ // add limited `ctx` object to the state for views
267+ ctx . state . ctx = { } ;
268+ ctx . state . ctx . get = ctx . get . bind ( ctx ) ;
269+ ctx . state . ctx . locale = ctx . locale ;
270+ ctx . state . ctx . path = ctx . path ;
271+ ctx . state . ctx . pathWithoutLocale = ctx . pathWithoutLocale ;
272+ ctx . state . ctx . query = ctx . query ;
273+ ctx . state . ctx . url = ctx . url ;
274+ return next ( ) ;
275+ } ) ;
276+
265277 // conditional-get
266278 app . use ( conditional ( ) ) ;
267279
@@ -332,6 +344,11 @@ class Web {
332344 } )
333345 ) ;
334346
347+ app . use ( ( ctx , next ) => {
348+ ctx . state . ctx . sessionId = ctx . sessionId ;
349+ return next ( ) ;
350+ } ) ;
351+
335352 // redirect loop (must come after sessions added)
336353 if ( this . config . redirectLoop ) {
337354 const redirectLoop = new RedirectLoop ( {
@@ -375,16 +392,6 @@ class Web {
375392 }
376393 }
377394
378- // add limited `ctx` object to the state for views
379- ctx . state . ctx = { } ;
380- ctx . state . ctx . get = ctx . get . bind ( ctx ) ;
381- ctx . state . ctx . locale = ctx . locale ;
382- ctx . state . ctx . path = ctx . path ;
383- ctx . state . ctx . pathWithoutLocale = ctx . pathWithoutLocale ;
384- ctx . state . ctx . query = ctx . query ;
385- ctx . state . ctx . sessionId = ctx . sessionId ;
386- ctx . state . ctx . url = ctx . url ;
387-
388395 return next ( ) ;
389396 } ) ;
390397
0 commit comments