mirror of https://github.com/pelias/api.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
517 B
25 lines
517 B
var defaultLabelGenerator = require('pelias-labels'); |
|
|
|
function setup(labelGenerator) { |
|
function middleware(req, res, next) { |
|
return assignLabel(req, res, next, labelGenerator || defaultLabelGenerator); |
|
} |
|
|
|
return middleware; |
|
} |
|
|
|
function assignLabel(req, res, next, labelGenerator) { |
|
|
|
// do nothing if there's nothing to process |
|
if (!res || !res.data) { |
|
return next(); |
|
} |
|
|
|
res.data.forEach(function (result) { |
|
result.label = labelGenerator(result); |
|
}); |
|
|
|
next(); |
|
} |
|
|
|
module.exports = setup;
|
|
|