Skip to content

Commit f29f17b

Browse files
Copilotnzakas
andauthored
fix: Add Netlify Edge function to block China from accessing feed.xml (#796)
* Initial plan * Initial plan for feed.xml geo-blocking edge function Co-authored-by: nzakas <38546+nzakas@users.noreply.github.com> * Add Netlify Edge function to block China from accessing feed.xml Co-authored-by: nzakas <38546+nzakas@users.noreply.github.com> * Simplify feed.ts edge function by removing unused variables Co-authored-by: nzakas <38546+nzakas@users.noreply.github.com> * Use config export in feed.ts instead of netlify.toml configuration Co-authored-by: nzakas <38546+nzakas@users.noreply.github.com> * Revert accidental changes to package-lock.json Co-authored-by: nzakas <38546+nzakas@users.noreply.github.com> * Apply suggestion from @nzakas --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: nzakas <38546+nzakas@users.noreply.github.com> Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com>
1 parent f6bf119 commit f29f17b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

functions/feed.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export const config = {
2+
path: "/feed.xml"
3+
}
4+
5+
export default async function handler(req: Request, context: any) {
6+
// Get the country code from Netlify's geo-location context
7+
const country = context.geo?.country?.code;
8+
9+
// Block requests from China (CN)
10+
if (country === "CN") {
11+
return new Response("Access denied", {
12+
status: 403,
13+
headers: {
14+
"Content-Type": "text/plain",
15+
},
16+
});
17+
}
18+
19+
}

0 commit comments

Comments
 (0)