Skip to content

Commit c2fdbd7

Browse files
committed
Update middlewares.js
1 parent bd40ed5 commit c2fdbd7

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/middlewares.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,20 @@ const checkIpRanges = (ip, ranges = []) => {
3030
}
3131
return ip;
3232
};
33+
const getType = address => (isIPv4(address) ? 'ipv4' : 'ipv6');
3334
const blocklist = new BlockList();
3435
for (const range of ranges) {
3536
if (range.includes('/')) {
3637
const [net, prefix] = range.split('/');
3738
const addr = transformIp(net);
38-
blocklist.addSubnet(addr, Number(prefix), isIPv4(addr) ? 'ipv4' : 'ipv6');
39+
blocklist.addSubnet(addr, Number(prefix), getType(addr));
3940
} else {
4041
const addr = transformIp(range);
41-
blocklist.addAddress(addr, isIPv4(addr) ? 'ipv4' : 'ipv6');
42+
blocklist.addAddress(addr, getType(addr));
4243
}
4344
}
4445
const client = transformIp(ip);
45-
return blocklist.check(client, isIPv4(client) ? 'ipv4' : 'ipv6');
46+
return blocklist.check(client, getType(client));
4647
};
4748

4849
// Checks that the request is authorized for this app and checks user

0 commit comments

Comments
 (0)