← Country website blocking
SERVER-SIDE COUNTRY RULES · DIRECT HTTP

Apply country rules in direct HTTP.

Look up the request country, apply your policy and decide before sending protected content.

1. Install and configure

Use your server runtime HTTP client; no SDK is required. Validate the framework-resolved visitor IP and keep ORIGOOO_API_KEY in the server environment. This JavaScript function is a helper for your existing request handler; replace the commented framework response placeholders with its real response methods.

Set ORIGOOO_API_KEY on your server. Use a secret key with lookup scope and the API origin https://orig.ooo. These SDKs are source downloads, not public package-registry releases.

2. Apply the rule before your response

This example blocks US and GB, allows other matched countries, and denies when location is unknown. Choose the unknown behaviour for your own service before deployment.

// Node.js 20+ server-side policy helper. Keep this key off the browser.
async function countryPolicy(visitorIp) {
  const response = await fetch(
    'https://orig.ooo/v1/ip/' + encodeURIComponent(visitorIp), {
      headers: {Authorization: 'Bearer ' + process.env.ORIGOOO_API_KEY},
      signal: AbortSignal.timeout(2000)
    });
  const body = await response.json();
  if (!response.ok) throw new Error(body.error?.code || body.code || 'lookup_failed');
  const country = body.country_code;
  return {country, allowed: !!country && !['US', 'GB'].includes(country)};
}
// Validate visitorIp as a public literal IP in your server framework.
// Apply this before rendering protected content:
// try { const result = await countryPolicy(visitorIp);
//       if (!result.allowed) return a403Response(); }
// catch { return yourExplicitUnknownCountryFallback(); }

Direct HTTP helper for your server framework.

3. Verify your request path

  1. Verify an allowed country reaches your application handler.
  2. Verify a blocked country returns 403 before protected content is rendered.
  3. Simulate a timeout, 429, missing country and invalid IP; verify your explicit unknown policy.
  4. Confirm untrusted forwarded headers cannot change the visitor IP.
  5. Keep administrator/health-route exceptions in trusted application code.

Choose when to use this

Use server policies for regional service availability and applications with a defined country policy. For an offer or message that merely appears or disappears, use the browser decision element. Browser hiding does not prevent downloading content already sent to the client.

The API supplies approximate geography. VPNs, mobile networks and proxies affect the result. Treat a country rule as one input to your application, not proof of residence.

Complete direct HTTP reference → · Error handling · Request speed and credits

YOUR NEXT BUILD STARTS HERE

Get your free API key.

1,000 monthly credits. No credit card required.

Account services are not connected in this preview. Explore the dashboard or download the implementation from your workspace.
Read the integration guide

Production accounts require verified email. Google OAuth and Paddle need deployment credentials.