2021-12-30 00:08:41 +01:00
|
|
|
import csurf from 'csurf/index.js';
|
|
|
|
import { Logger } from './logger.js';
|
2022-01-16 21:55:50 +01:00
|
|
|
import { Common } from './common.js';
|
2021-12-30 00:08:41 +01:00
|
|
|
class CSRF {
|
|
|
|
constructor() {
|
|
|
|
this.csrfProtection = csurf({ cookie: true });
|
|
|
|
this.logger = Logger;
|
2022-01-16 21:55:50 +01:00
|
|
|
this.common = Common;
|
2021-12-30 00:08:41 +01:00
|
|
|
}
|
|
|
|
mount(app) {
|
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;
|