2
0
mirror of https://github.com/Ride-The-Lightning/RTL synced 2024-11-11 13:10:41 +00:00
RTL/backend/utils/csrf.js

21 lines
739 B
JavaScript
Raw Normal View History

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