Skip to content

Commit

Permalink
close-airdrop (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos authored Feb 27, 2024
1 parent 8bdffef commit e733ec5
Showing 1 changed file with 10 additions and 40 deletions.
50 changes: 10 additions & 40 deletions frontend/middleware.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
import { NextResponse } from 'next/server'

// Block visitors from these countries
const BLOCKED_COUNTRIES = [
'BY',
'CF',
'CD',
'KP',
'CU',
'IR',
'LY',
'SO',
'SD',
'SY',
'US',
'GB',
'YE',
'ZW',
]

// Limit middleware pathname config
export const config = {
matcher: '/',
}

export function middleware(req) {
// Extract country
const country = req.geo.country

if (BLOCKED_COUNTRIES.includes(country)) {
// Error 451: Unavailable For Legal Reasons
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/451
const body = `
const body = `
<html>
<head>
<link
Expand Down Expand Up @@ -59,21 +33,17 @@ export function middleware(req) {
</style>
</head>
<body>
<h1>Error 451: Unavailable For Legal Reasons</h1>
<p>This Site is not available to residents of Belarus, the Central African Republic, The Democratic Republic of Congo, the Democratic People's Republic of Korea, the Crimea, Donetsk People's Republic, and Luhansk People's Republic regions of Ukraine, Cuba, Iran, Libya, Somalia, Sudan, South Sudan, Syria, the USA, the United Kingdom, Yemen, Zimbabwe and any other jurisdiction in which accessing or using the Site is prohibited (the "Prohibited Jurisdictions").</p>
<h1>The airdrop claim period has ended</h1>
<p>To stay in touch with future Pyth community initiatives head over to our <a href="https://discord.gg/invite/PythNetwork">Discord</a> </p>
</body>
</html>
`

// NextResponse object does not have a body property so we use Response instead
return new Response(body, {
status: 451,
headers: {
'Content-Type': 'text/html',
},
})
} else {
// Continue with the request if the country is not blocked
return NextResponse.next()
}
// NextResponse object does not have a body property so we use Response instead
return new Response(body, {
status: 200,
headers: {
'Content-Type': 'text/html',
},
})
}

0 comments on commit e733ec5

Please sign in to comment.