Files
hudozka/src/routes/redirect.js
T
2016-02-27 19:42:44 +03:00

20 lines
397 B
JavaScript

/**
*
* @param redirectionTable
* [{String url, String redirect}, ...]
* @returns {*}
*/
export function redirect(redirectionTable) {
return function *(next) {
let path = this.request.path;
let record = redirectionTable.find(i => i.url === path);
if(record){
this.redirect(record.redirect);
return;
}
yield next;
};
}