This commit is contained in:
2020-04-09 21:12:36 +02:00
parent bc50897afc
commit 2dc969a47d
5 changed files with 406 additions and 27 deletions

View File

@ -7,7 +7,9 @@ export default abstract class Handler {
private _method_handlers: Record<string, Function> = {};
protected register_handler (f: Function, method?: string): void {
if (typeof method === 'undefined') { this._handlers.push (f); }
if (typeof method === 'undefined') {
this._handlers.push (f);
}
else {
const m = method.toUpperCase ();
if (typeof this._method_handlers[m] !== 'undefined')
@ -16,7 +18,10 @@ export default abstract class Handler {
}
}
private async run_method_handler (method: string, t: Transaction): Promise<void> {
private async run_method_handler (
method: string,
t: Transaction
): Promise<void> {
const m = method.toUpperCase ();
if (typeof this._method_handlers[m] !== 'undefined')
await this._method_handlers[m] (t);

View File

@ -1,5 +1,7 @@
import { Application } from 'express';
import Handler from './classes/Handler';
import Session from './classes/Session';
import Transaction from './classes/Transaction';
/**
* register an array of handlers to an express app
@ -15,6 +17,4 @@ export default function load_handlers (
app.use (h.path, h.run_http_handler);
}
export * from './classes/Session';
export * from './classes/Transaction';
export * from './classes/Handler';
export { Handler, Session, Transaction, load_handlers };