lambder 1.0.110 → 1.0.111
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/dist/Lambder.js +26 -0
- package/package.json +1 -1
- package/src/Lambder.ts +25 -0
package/dist/Lambder.js
CHANGED
|
@@ -278,6 +278,7 @@ export default class Lambder {
|
|
|
278
278
|
return resolver.cors();
|
|
279
279
|
const firstMatchedAction = this.actionList.find(action => action.conditionFn(ctx));
|
|
280
280
|
if (firstMatchedAction) {
|
|
281
|
+
// Run beforeRender hooks
|
|
281
282
|
for (const hook of this.hookList["beforeRender"]) {
|
|
282
283
|
const hookCtx = await hook.hookFn(ctx, resolver);
|
|
283
284
|
if (hookCtx instanceof Error) {
|
|
@@ -285,7 +286,9 @@ export default class Lambder {
|
|
|
285
286
|
}
|
|
286
287
|
ctx = hookCtx;
|
|
287
288
|
}
|
|
289
|
+
// Run matched action
|
|
288
290
|
let response = await firstMatchedAction.actionFn(ctx, resolver);
|
|
291
|
+
// Run afterRender hooks
|
|
289
292
|
for (const hook of this.hookList["afterRender"]) {
|
|
290
293
|
const hookResponse = await hook.hookFn(ctx, resolver, response);
|
|
291
294
|
if (hookResponse instanceof Error) {
|
|
@@ -293,6 +296,29 @@ export default class Lambder {
|
|
|
293
296
|
}
|
|
294
297
|
response = hookResponse;
|
|
295
298
|
}
|
|
299
|
+
// Apply session cookie if needed.
|
|
300
|
+
if ((ctx.session?.sessionToken ?? null) !== (ctx?.cookie?.[this.sessionTokenCookieKey] ?? null)) {
|
|
301
|
+
// Add session cookies
|
|
302
|
+
if (ctx.session?.sessionToken) {
|
|
303
|
+
response.multiValueHeaders = {
|
|
304
|
+
...(response.multiValueHeaders || {}),
|
|
305
|
+
"Set-Cookie": [
|
|
306
|
+
`${this.sessionTokenCookieKey}=${ctx.session.sessionToken}; Expires=${new Date(ctx.session.expiresAt * 1000).toUTCString()}; Path=/; SameSite=Lax; Secure`,
|
|
307
|
+
`${this.sessionCsrfCookieKey}=${ctx.session.csrfToken}; Expires=${new Date(ctx.session.expiresAt * 1000).toUTCString()}; Path=/; SameSite=Lax; Secure`,
|
|
308
|
+
],
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
// Delete session cookies
|
|
313
|
+
response.multiValueHeaders = {
|
|
314
|
+
...(response.multiValueHeaders || {}),
|
|
315
|
+
"Set-Cookie": [
|
|
316
|
+
`${this.sessionTokenCookieKey}=0; Expires=${new Date(Date.now() - 100000).toUTCString()}; Path=/; SameSite=Lax; Secure`,
|
|
317
|
+
`${this.sessionCsrfCookieKey}=0; Expires=${new Date(Date.now() - 100000).toUTCString()}; Path=/; SameSite=Lax; Secure`,
|
|
318
|
+
],
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
}
|
|
296
322
|
resolve(response);
|
|
297
323
|
}
|
|
298
324
|
else {
|
package/package.json
CHANGED
package/src/Lambder.ts
CHANGED
|
@@ -356,17 +356,42 @@ export default class Lambder {
|
|
|
356
356
|
|
|
357
357
|
const firstMatchedAction = this.actionList.find(action => action.conditionFn(ctx));
|
|
358
358
|
if(firstMatchedAction){
|
|
359
|
+
// Run beforeRender hooks
|
|
359
360
|
for(const hook of this.hookList["beforeRender"]){
|
|
360
361
|
const hookCtx = await hook.hookFn(ctx, resolver);
|
|
361
362
|
if(hookCtx instanceof Error){ throw hookCtx; }
|
|
362
363
|
ctx = hookCtx;
|
|
363
364
|
}
|
|
365
|
+
// Run matched action
|
|
364
366
|
let response = await firstMatchedAction.actionFn(ctx, resolver);
|
|
367
|
+
// Run afterRender hooks
|
|
365
368
|
for(const hook of this.hookList["afterRender"]){
|
|
366
369
|
const hookResponse = await hook.hookFn(ctx, resolver, response);
|
|
367
370
|
if(hookResponse instanceof Error){ throw hookResponse; }
|
|
368
371
|
response = hookResponse;
|
|
369
372
|
}
|
|
373
|
+
// Apply session cookie if needed.
|
|
374
|
+
if((ctx.session?.sessionToken ?? null) !== (ctx?.cookie?.[this.sessionTokenCookieKey] ?? null)){
|
|
375
|
+
// Add session cookies
|
|
376
|
+
if(ctx.session?.sessionToken){
|
|
377
|
+
response.multiValueHeaders = {
|
|
378
|
+
...(response.multiValueHeaders || {}),
|
|
379
|
+
"Set-Cookie": [
|
|
380
|
+
`${this.sessionTokenCookieKey}=${ctx.session.sessionToken}; Expires=${new Date(ctx.session.expiresAt * 1000).toUTCString()}; Path=/; SameSite=Lax; Secure`,
|
|
381
|
+
`${this.sessionCsrfCookieKey}=${ctx.session.csrfToken}; Expires=${new Date(ctx.session.expiresAt * 1000).toUTCString()}; Path=/; SameSite=Lax; Secure`,
|
|
382
|
+
],
|
|
383
|
+
};
|
|
384
|
+
}else{
|
|
385
|
+
// Delete session cookies
|
|
386
|
+
response.multiValueHeaders = {
|
|
387
|
+
...(response.multiValueHeaders || {}),
|
|
388
|
+
"Set-Cookie": [
|
|
389
|
+
`${this.sessionTokenCookieKey}=0; Expires=${new Date(Date.now() - 100000).toUTCString()}; Path=/; SameSite=Lax; Secure`,
|
|
390
|
+
`${this.sessionCsrfCookieKey}=0; Expires=${new Date(Date.now() - 100000).toUTCString()}; Path=/; SameSite=Lax; Secure`,
|
|
391
|
+
],
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
}
|
|
370
395
|
resolve(response);
|
|
371
396
|
}else{
|
|
372
397
|
return this.handleNoMatchedAction(ctx, resolver);
|