Logging & moment.js

This commit is contained in:
garrettmills
2020-07-29 22:37:16 -05:00
parent a04f083dbb
commit 0d4881de1f
5 changed files with 17 additions and 18 deletions

View File

@@ -27,15 +27,20 @@ export default class Kernel extends AppClass {
protected postflight: Collection<Module> = new Collection<Module>()
public async handle(request: Request): Promise<Request> {
const logger = this.make(Logging)
for ( const module of this.preflight.toArray() ) {
logger.verbose(`Applying pre-flight HTTP kernel module: ${module.constructor.name}`)
request = await module.apply(request)
}
if ( this.inflight ) {
logger.verbose(`Applying core HTTP kernel module: ${this.inflight.constructor.name}`)
request = await this.inflight.apply(request)
}
for ( const module of this.postflight.toArray() ) {
logger.verbose(`Applying post-flight HTTP kernel module: ${module.constructor.name}`)
request = await module.apply(request)
}
@@ -54,6 +59,7 @@ export default class Kernel extends AppClass {
let found_index = this.preflight.find((mod: Module) => mod instanceof other)
if ( typeof found_index !== 'undefined' ) {
this.preflight = this.preflight.put(found_index, this.make(module))
return this
} else {
found_index = this.postflight.find((mod: Module) => mod instanceof other)
}
@@ -75,6 +81,7 @@ export default class Kernel extends AppClass {
let found_index = this.preflight.find((mod: Module) => mod instanceof other)
if ( typeof found_index !== 'undefined' ) {
this.preflight = this.preflight.put(found_index + 1, this.make(module))
return this
} else {
found_index = this.postflight.find((mod: Module) => mod instanceof other)
}
@@ -82,7 +89,6 @@ export default class Kernel extends AppClass {
if ( typeof found_index !== 'undefined' ) {
this.postflight = this.postflight.put(found_index + 1, this.make(module))
} else {
console.log(this.preflight, this.postflight)
throw new KernelModuleNotFoundError(other.name)
}

View File

@@ -4,6 +4,7 @@ import {Request} from '../../Request.ts'
import PrepareRequest from './PrepareRequest.ts'
import Utility from '../../../service/utility/Utility.ts'
import {Injectable} from '../../../../../di/src/decorator/Injection.ts'
import {Logging} from '../../../service/logging/Logging.ts'
@Injectable()
export default class SetSessionCookie extends Module {
@@ -20,7 +21,10 @@ export default class SetSessionCookie extends Module {
public async apply(request: Request): Promise<Request> {
if ( !(await request.cookies.has('daton.session')) ) {
await request.cookies.set('daton.session', `${this.utility.uuid()}-${this.utility.uuid()}`)
const cookie = `${this.utility.uuid()}-${this.utility.uuid()}`
this.make(Logging).verbose(`Starting session: ${cookie}`)
await request.cookies.set('daton.session', cookie)
}
return request
}