How to block audience?


Is there any way that my page can only be viewed in Canada?

If you are using Node.js (you have to make your site dynamic for something like this to work) you can use the code below which gets the users country based on their ip address with ipwhois.

// NOTE: make sure you have node-fetch and express imported

app.get("/", (request, response) => {

  // get user ip
  var ip = request.header("x-forwarded-for").split(",")[0] || request.connection.remoteAddress;

  // get ip info from api
  fetch("" + ip)
    .then(res => res.json())
    .then(json => {

    // block requests not from canada
    if (json.country_code !== "CA") return response.end(403)

    // ...



Thank you, I will try it out. It will only work for Node.js?

You can use the ipwhois API in any language with an HTTP client.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.