lib/src/http/kernel/module/PersistSessionHTTPModule.ts

25 lines
775 B
TypeScript
Raw Normal View History

2021-06-03 03:36:25 +00:00
import {HTTPKernelModule} from '../HTTPKernelModule'
import {Injectable} from '../../../di'
import {HTTPKernel} from '../HTTPKernel'
import {Request} from '../../lifecycle/Request'
import {Session} from '../../session/Session'
2021-03-07 19:26:14 +00:00
2021-03-25 13:50:13 +00:00
/**
* HTTP kernel module that runs after the main logic in the request to persist
* the session data to the driver's backend.
*/
2021-03-07 19:26:14 +00:00
@Injectable()
export class PersistSessionHTTPModule extends HTTPKernelModule {
2021-03-09 15:42:19 +00:00
public readonly executeWithBlockingWriteback = true
2021-06-03 03:36:25 +00:00
public static register(kernel: HTTPKernel): void {
2021-03-07 19:26:14 +00:00
kernel.register(this).last()
}
public async apply(request: Request): Promise<Request> {
const session = <Session> request.make(Session)
await session.persist()
return request
}
}