|
@@ -3,6 +3,8 @@ import { createHash } from 'crypto';
|
|
|
import { NextFunction, Request, Response, Router, RouterOptions, json as jsonBodyParser } from 'express';
|
|
import { NextFunction, Request, Response, Router, RouterOptions, json as jsonBodyParser } from 'express';
|
|
|
import moment from 'moment';
|
|
import moment from 'moment';
|
|
|
|
|
|
|
|
|
|
+import { ChatController } from '../../controllers/chat-controller.class';
|
|
|
|
|
+import { ControllerPool } from '../../controllers/lib/controller-pool.interface';
|
|
|
import { AuthenticationException } from '../../model/err/authentication.exception';
|
|
import { AuthenticationException } from '../../model/err/authentication.exception';
|
|
|
import { SessionHandler } from './session-handler.class';
|
|
import { SessionHandler } from './session-handler.class';
|
|
|
|
|
|
|
@@ -10,14 +12,13 @@ const STATIC_USERS = {
|
|
|
testuser: 'bc2d5cc456b81caa403661411cc72a309c39677d035b74b713a5ba02412d9eff' // pass1234
|
|
testuser: 'bc2d5cc456b81caa403661411cc72a309c39677d035b74b713a5ba02412d9eff' // pass1234
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-export abstract class HandlerBase {
|
|
|
|
|
|
|
+export abstract class HandlerBase implements ControllerPool {
|
|
|
private _router: Router;
|
|
private _router: Router;
|
|
|
|
|
+ private _chatCtrl?: ChatController;
|
|
|
|
|
|
|
|
constructor(private sessionHandler?: SessionHandler, auth?: boolean, options?: RouterOptions) {
|
|
constructor(private sessionHandler?: SessionHandler, auth?: boolean, options?: RouterOptions) {
|
|
|
this._router = Router(options);
|
|
this._router = Router(options);
|
|
|
|
|
|
|
|
- this.router.use(jsonBodyParser());
|
|
|
|
|
-
|
|
|
|
|
if (this.sessionHandler) {
|
|
if (this.sessionHandler) {
|
|
|
this._router.use(this.sessionHandler.handler);
|
|
this._router.use(this.sessionHandler.handler);
|
|
|
if (auth) {
|
|
if (auth) {
|
|
@@ -26,12 +27,32 @@ export abstract class HandlerBase {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected useCsrfMiddleware(options?: { ignorePath: string[] }) {
|
|
|
|
|
|
|
+ public get router(): Router {
|
|
|
|
|
+ return this._router;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public get chat(): ChatController {
|
|
|
|
|
+ if (!this._chatCtrl) {
|
|
|
|
|
+ this._chatCtrl = new ChatController(this);
|
|
|
|
|
+ }
|
|
|
|
|
+ return this._chatCtrl;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ protected avoidCache = (req, res, next) => {
|
|
|
|
|
+ res.setHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
|
|
|
|
|
+ res.setHeader('Last-Modified', `${moment().format('ddd, DD MMM YYYY HH:mm:ss')} CEST`);
|
|
|
|
|
+ res.setHeader('Cache-Control', 'no-cache, max-age=0, must-revalidate, no-store');
|
|
|
|
|
+ res.setHeader('Pragma', 'no-cache');
|
|
|
|
|
+
|
|
|
|
|
+ next();
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ protected csrf(options?: { ignorePath: string[] }) {
|
|
|
options = {
|
|
options = {
|
|
|
ignorePath: [],
|
|
ignorePath: [],
|
|
|
...options
|
|
...options
|
|
|
};
|
|
};
|
|
|
- this.router.use((req, res, next) => {
|
|
|
|
|
|
|
+ return (req, res, next) => {
|
|
|
if (options.ignorePath.includes(req.path)) {
|
|
if (options.ignorePath.includes(req.path)) {
|
|
|
return next();
|
|
return next();
|
|
|
}
|
|
}
|
|
@@ -47,22 +68,9 @@ export abstract class HandlerBase {
|
|
|
});
|
|
});
|
|
|
next();
|
|
next();
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public get router(): Router {
|
|
|
|
|
- return this._router;
|
|
|
|
|
|
|
+ };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected avoidCache = (req, res, next) => {
|
|
|
|
|
- res.setHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
|
|
|
|
|
- res.setHeader('Last-Modified', `${moment().format('ddd, DD MMM YYYY HH:mm:ss')} CEST`);
|
|
|
|
|
- res.setHeader('Cache-Control', 'no-cache, max-age=0, must-revalidate, no-store');
|
|
|
|
|
- res.setHeader('Pragma', 'no-cache');
|
|
|
|
|
-
|
|
|
|
|
- next();
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
private async authHandler(
|
|
private async authHandler(
|
|
|
req: Request<any, any, any, any, Record<string, any>>,
|
|
req: Request<any, any, any, any, Record<string, any>>,
|
|
|
res: Response<any, Record<string, any>>,
|
|
res: Response<any, Record<string, any>>,
|