Skip to content

Commit 532dbc5

Browse files
committed
Add path ignore
1 parent 9948362 commit 532dbc5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
const Hashids = require('hashids');
44
const NODE_ENV = process.env.NODE_ENV;
55
const isProduction = (NODE_ENV === 'production');
6+
const IGNORE_AUTH_PATH_REGEX = process.env.IGNORE_AUTH_PATH_REGEX || /(web)/;
7+
8+
function isIgnoredPath(path) {
9+
return path.search(IGNORE_AUTH_PATH_REGEX) >= 0;
10+
}
611

712
function hashKeyMiddlewareWrapper (options = {
813
salt: process.env.SALT || 'my salt',
@@ -14,6 +19,10 @@ function hashKeyMiddlewareWrapper (options = {
1419
const HASHKEY_ALIVE_TIME = options.hashkeyAliveTime * 60 * 1000;
1520

1621
return function hashKeyMiddleware(req, res, next) {
22+
if (isIgnoredPath(req.path)) {
23+
return next();
24+
}
25+
1726
const hashKey = req.query.hashkey || req.query.access_token;
1827
const decodedKey = idHashids.decode(hashKey);
1928
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;

0 commit comments

Comments
 (0)