-
Notifications
You must be signed in to change notification settings - Fork 466
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18758 from cockroachdb/feat/netlify-block
netlify block
- Loading branch information
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { Config, Context } from "@netlify/edge-functions"; | ||
|
||
export default async function handler(request: Request, context: Context) { | ||
const bytedanceUserAgents = [ | ||
'Bytespider; [email protected]' | ||
// Add other Bytedance user agents if needed | ||
]; | ||
|
||
// Get the user agent from the request headers | ||
const userAgent = request.headers.get('user-agent') || ''; | ||
|
||
// Check if the user agent matches any of the Bytedance user agents | ||
const isBytedanceBot = bytedanceUserAgents.some(ua => userAgent.includes(ua)); | ||
|
||
// Block access if it is a Bytedance user agent | ||
if (isBytedanceBot) { | ||
return new Response('Access Denied', { | ||
status: 403, | ||
headers: { 'Content-Type': 'text/plain' } | ||
}); | ||
} | ||
|
||
// Log "hello" before continuing the request | ||
console.log("hello"); | ||
|
||
// Continue the request chain and get the response from the next handler or the origin server | ||
return context.next(); | ||
} | ||
|
||
export const config: Config = { | ||
path: "/*", // This path can be adjusted based on where you want to apply this edge function | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters