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'
|
|
|
|
];
|
|
|
|
|
2015-09-23 21:54:08 +00:00
|
|
|
const pathsWhiteList = [
|
|
|
|
'news',
|
|
|
|
'challenges',
|
|
|
|
'map',
|
2015-12-28 20:41:37 +00:00
|
|
|
'news',
|
|
|
|
'commit'
|
2015-09-23 21:54:08 +00:00
|
|
|
];
|
|
|
|
|
2015-08-18 22:22:28 +00:00
|
|
|
const pathsOfNoReturnRegex = new RegExp(pathsOfNoReturn.join('|'), 'i');
|
2015-09-23 21:54:08 +00:00
|
|
|
const whiteListRegex = new RegExp(pathsWhiteList.join('|'), 'i');
|
2015-08-18 22:22:28 +00:00
|
|
|
|
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
|
|
|
|
2015-09-23 21:54:08 +00:00
|
|
|
if (
|
|
|
|
req.method !== 'GET' ||
|
|
|
|
pathsOfNoReturnRegex.test(path) ||
|
|
|
|
!whiteListRegex.test(path) ||
|
2015-09-23 22:05:27 +00:00
|
|
|
(/news/i).test(path) && (/hot/i).test(req.path)
|
2015-09-23 21:54:08 +00:00
|
|
|
) {
|
2015-08-04 08:25:34 +00:00
|
|
|
return next();
|
|
|
|
}
|
2016-01-17 07:15:05 +00:00
|
|
|
req.session.returnTo = req.originalUrl === '/map-aside'
|
|
|
|
? '/map' : req.originalUrl;
|
2015-08-04 08:25:34 +00:00
|
|
|
next();
|
|
|
|
};
|
|
|
|
}
|