2021-12-29 23:08:41 +00:00
|
|
|
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 CORS {
|
|
|
|
constructor() {
|
|
|
|
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: 'CORS', msg: 'Setting up CORS..' });
|
2021-12-29 23:08:41 +00:00
|
|
|
app.use((req, res, next) => {
|
|
|
|
res.setHeader('Cache-Control', 'no-cache');
|
|
|
|
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization, filePath');
|
|
|
|
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, DELETE, OPTIONS');
|
|
|
|
if (process.env.NODE_ENV === 'development') {
|
2022-03-05 17:13:02 +00:00
|
|
|
res.setHeader('Access-Control-Allow-Credentials', 'true');
|
2021-12-29 23:08:41 +00:00
|
|
|
res.setHeader('Access-Control-Allow-Origin', req.headers.origin ? req.headers.origin : req.headers.host ? req.headers.host : '');
|
|
|
|
}
|
|
|
|
next();
|
|
|
|
});
|
2022-01-16 20:55:50 +00:00
|
|
|
this.logger.log({ selectedNode: this.common.initSelectedNode, level: 'INFO', fileName: 'CORS', msg: 'CORS Set' });
|
2021-12-29 23:08:41 +00:00
|
|
|
return app;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
}
|
|
|
|
export default new CORS;
|