2021-12-30 00:08:41 +01:00
|
|
|
import csurf from 'csurf/index.js';
|
|
|
|
import { Application } from 'express';
|
|
|
|
import { Logger, LoggerService } from './logger.js';
|
2022-01-16 21:55:50 +01:00
|
|
|
import { Common, CommonService } from './common.js';
|
2021-12-30 00:08:41 +01:00
|
|
|
|
|
|
|
class CSRF {
|
|
|
|
|
|
|
|
public csrfProtection = csurf({ cookie: true });
|
|
|
|
public logger: LoggerService = Logger;
|
2022-01-16 21:55:50 +01:00
|
|
|
public common: CommonService = Common;
|
2021-12-30 00:08:41 +01:00
|
|
|
|
|
|
|
public mount(app: Application): Application {
|
2022-01-16 21:55:50 +01:00
|
|
|
this.logger.log({ selectedNode: this.common.initSelectedNode, level: 'INFO', fileName: 'CSRF', msg: 'Setting up CSRF..' });
|
2021-12-30 00:08:41 +01:00
|
|
|
if (process.env.NODE_ENV !== 'development') {
|
|
|
|
app.use((req, res, next) => this.csrfProtection(req, res, next));
|
|
|
|
}
|
2022-01-16 21:55:50 +01:00
|
|
|
this.logger.log({ selectedNode: this.common.initSelectedNode, level: 'INFO', fileName: 'CSRF', msg: 'CSRF Set' });
|
2021-12-30 00:08:41 +01:00
|
|
|
return app;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new CSRF;
|