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();
|
|
|
|
}
|
|
|
|
|
2020-06-02 15:00:45 +08:00
|
|
|
const { mapConfigProvider, logger } = res.locals;
|
2018-03-21 21:11:54 +08:00
|
|
|
|
|
|
|
mapConfigProvider.getAffectedTables((err, affectedTables) => {
|
|
|
|
if (err) {
|
2020-06-03 23:32:16 +08:00
|
|
|
err.message = `Error generating Cache Channel Header. ${err.message}`;
|
|
|
|
logger.warn({ error: err });
|
2018-03-21 21:11:54 +08:00
|
|
|
return next();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!affectedTables) {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
|
|
|
|
res.set('X-Cache-Channel', affectedTables.getCacheChannel());
|
|
|
|
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|