Skip to content

Block China and Singapore traffic? #45

Description

@bryanfriedman

Could use Netlify edge function to block this traffic which us almost 100% bots and prevent it from cluttering up GA.

// in netlify/edge-functions/block-countries.ts
export default async (request: Request) => {
  const country = request.headers.get("x-nf-geo-country");

  if (country === "CN" || country === "SG") {
    return new Response("Forbidden", { status: 403 });
  }

  return fetch(request);
};
# in netlify.toml
[[edge_functions]]
function = "block-countries"
path = "/*"

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions