chore(server): Move api-server in to it's own DIR
This commit is contained in:
committed by
mrugesh mohapatra
parent
9fba6bce4c
commit
46a217d0a5
43
api-server/server/middlewares/add-return-to.js
Normal file
43
api-server/server/middlewares/add-return-to.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const pathsOfNoReturn = [
|
||||
'link',
|
||||
'auth',
|
||||
'login',
|
||||
'logout',
|
||||
'signin',
|
||||
'signup',
|
||||
'fonts',
|
||||
'favicon',
|
||||
'js',
|
||||
'css'
|
||||
];
|
||||
|
||||
const pathsWhiteList = [
|
||||
'news',
|
||||
'challenges',
|
||||
'map',
|
||||
'news',
|
||||
'commit'
|
||||
];
|
||||
|
||||
const pathsOfNoReturnRegex = new RegExp(pathsOfNoReturn.join('|'), 'i');
|
||||
const whiteListRegex = new RegExp(pathsWhiteList.join('|'), 'i');
|
||||
|
||||
export default function addReturnToUrl() {
|
||||
return function(req, res, next) {
|
||||
// Remember original destination before login.
|
||||
var path = req.path.split('/')[1];
|
||||
|
||||
if (
|
||||
req.method !== 'GET' ||
|
||||
pathsOfNoReturnRegex.test(path) ||
|
||||
!whiteListRegex.test(path) ||
|
||||
(/hot/i).test(req.path)
|
||||
) {
|
||||
return next();
|
||||
}
|
||||
req.session.returnTo = req.originalUrl.includes('/map') ?
|
||||
'/' :
|
||||
req.originalUrl;
|
||||
return next();
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user