Move middleware

This commit is contained in:
Daniel García Aubert
2018-03-20 09:34:06 +01:00
parent 9211fa065b
commit 325bdfe92f
+17 -17
View File
@@ -89,6 +89,7 @@ MapController.prototype.composeCreateMapMiddleware = function (useTemplate = fal
augmentLayergroupData(),
getAffectedTables(this.pgConnection, this.layergroupAffectedTables),
setCacheChannel(),
setSurrogateKeyHeader(this.surrogateKeysCache),
setLastModified(),
setLastUpdatedTimeToLayergroup(),
setCacheControl(),
@@ -99,7 +100,6 @@ MapController.prototype.composeCreateMapMiddleware = function (useTemplate = fal
setTurboCartoMetadataToLayergroup(this.layergroupMetadata),
setAggregationMetadataToLayergroup(this.layergroupMetadata),
setTilejsonMetadataToLayergroup(this.layergroupMetadata),
setSurrogateKeyHeader(this.surrogateKeysCache),
sendResponse(),
augmentError({ label, addContext })
];
@@ -393,6 +393,22 @@ function setCacheChannel () {
};
}
function setSurrogateKeyHeader (surrogateKeysCache) {
return function setSurrogateKeyHeaderMiddleware(req, res, next) {
const { affectedTables, user, templateName } = res.locals;
if (req.method === 'GET' && affectedTables.tables && affectedTables.tables.length > 0) {
surrogateKeysCache.tag(res, affectedTables);
}
if (templateName) {
surrogateKeysCache.tag(res, new NamedMapsCacheEntry(user, templateName));
}
next();
};
}
function setLastModified () {
return function setLastModifiedMiddleware (req, res, next) {
if (req.method === 'GET') {
@@ -542,22 +558,6 @@ function setTilejsonMetadataToLayergroup (layergroupMetadata) {
};
}
function setSurrogateKeyHeader (surrogateKeysCache) {
return function setSurrogateKeyHeaderMiddleware(req, res, next) {
const { affectedTables, user, templateName } = res.locals;
if (req.method === 'GET' && affectedTables.tables && affectedTables.tables.length > 0) {
surrogateKeysCache.tag(res, affectedTables);
}
if (templateName) {
surrogateKeysCache.tag(res, new NamedMapsCacheEntry(user, templateName));
}
next();
};
}
function augmentError (options) {
const { addContext = false, label = 'MAPS CONTROLLER' } = options;