2015-08-18 22:22:28 +00:00
|
|
|
const pathsOfNoReturn = [
|
|
|
|
'link',
|
2015-08-18 23:00:27 +00:00
|
|
|
'bower_components',
|
2015-08-18 22:22:28 +00:00
|
|
|
'auth',
|
|
|
|
'login',
|
|
|
|
'logout',
|
|
|
|
'signin',
|
|
|
|
'signup',
|
|
|
|
'fonts',
|
|
|
|
'favicon',
|
|
|
|
'js',
|
|
|
|
'css'
|
|
|
|
];
|
|
|
|
|
|
|
|
const pathsOfNoReturnRegex = new RegExp(pathsOfNoReturn.join('|'), 'i');
|
|
|
|
|
2015-08-04 08:25:34 +00:00
|
|
|
export default function addReturnToUrl() {
|
|
|
|
return function(req, res, next) {
|
|
|
|
// Remember original destination before login.
|
|
|
|
var path = req.path.split('/')[1];
|
2015-08-18 22:22:28 +00:00
|
|
|
|
|
|
|
if (req.method !== 'GET') {
|
2015-08-04 08:25:34 +00:00
|
|
|
return next();
|
2015-08-18 22:22:28 +00:00
|
|
|
}
|
|
|
|
if (pathsOfNoReturnRegex.test(path)) {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
if (/\/stories\/\w+/i.test(req.path)) {
|
2015-08-04 08:25:34 +00:00
|
|
|
return next();
|
|
|
|
}
|
|
|
|
req.session.returnTo = req.path;
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
}
|