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