Checking package size effects when we remove zod from middleware
parent
1bf50e09cd
commit
ecc2038411
|
@ -1,5 +1,4 @@
|
|||
import type { NextApiRequest } from "next";
|
||||
import z from "zod";
|
||||
|
||||
export function parseIpFromHeaders(value: string | string[]) {
|
||||
return Array.isArray(value) ? value[0] : value.split(",")[0];
|
||||
|
@ -16,13 +15,11 @@ export default function getIP(request: Request | NextApiRequest) {
|
|||
return xff ? parseIpFromHeaders(xff) : "127.0.0.1";
|
||||
}
|
||||
|
||||
const banlistSchema = z.array(z.string());
|
||||
|
||||
export function isIpInBanlist(request: Request | NextApiRequest) {
|
||||
const IP = getIP(request);
|
||||
const rawBanListJson = process.env.IP_BANLIST || "[]";
|
||||
const banList = banlistSchema.parse(JSON.parse(rawBanListJson));
|
||||
if (banList.includes(IP)) {
|
||||
const banList = JSON.parse(rawBanListJson);
|
||||
if (Array.isArray(banList) && banList.includes(IP)) {
|
||||
console.log(`Found banned IP: ${IP} in IP_BANLIST`);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue