2018-10-23 23:45:42 +08:00
|
|
|
'use strict';
|
|
|
|
|
2018-03-21 21:11:54 +08:00
|
|
|
module.exports = function setCacheChannelHeader () {
|
|
|
|
return function setCacheChannelHeaderMiddleware (req, res, next) {
|
|
|
|
if (req.method !== 'GET') {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
|
|
|
|
const { mapConfigProvider } = res.locals;
|
|
|
|
|
|
|
|
mapConfigProvider.getAffectedTables((err, affectedTables) => {
|
|
|
|
if (err) {
|
|
|
|
global.logger.warn('ERROR generating Cache Channel Header:', err);
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!affectedTables) {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
|
|
|
|
res.set('X-Cache-Channel', affectedTables.getCacheChannel());
|
|
|
|
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|