@ladjs/web 20.0.3 → 20.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +17 -10
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -262,6 +262,18 @@ class Web {
|
|
|
262
262
|
app.use(i18n.redirect);
|
|
263
263
|
}
|
|
264
264
|
|
|
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
|
+
|
|
265
277
|
// conditional-get
|
|
266
278
|
app.use(conditional());
|
|
267
279
|
|
|
@@ -332,6 +344,11 @@ class Web {
|
|
|
332
344
|
})
|
|
333
345
|
);
|
|
334
346
|
|
|
347
|
+
app.use((ctx, next) => {
|
|
348
|
+
ctx.state.ctx.sessionId = ctx.sessionId;
|
|
349
|
+
return next();
|
|
350
|
+
});
|
|
351
|
+
|
|
335
352
|
// redirect loop (must come after sessions added)
|
|
336
353
|
if (this.config.redirectLoop) {
|
|
337
354
|
const redirectLoop = new RedirectLoop({
|
|
@@ -375,16 +392,6 @@ class Web {
|
|
|
375
392
|
}
|
|
376
393
|
}
|
|
377
394
|
|
|
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
|
-
|
|
388
395
|
return next();
|
|
389
396
|
});
|
|
390
397
|
|
package/package.json
CHANGED