+ redirect table support

This commit is contained in:
tmshv committed 2016-02-27 19:42:44 +03:00
1 parent 80719055b3
commit 26c0534372
4 files changed
+41 -1

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
/**
*
* @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;
};
}