From fd833c3dc532e6a5e0b320d2651ac32fb471d0e6 Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Tue, 23 Jul 2024 20:18:39 +0530 Subject: [PATCH 01/26] netlify block --- src/current/_layouts/default.html | 1 + src/current/js/blockBytedance.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/current/js/blockBytedance.js diff --git a/src/current/_layouts/default.html b/src/current/_layouts/default.html index 0294f14c0ad..192637056cb 100755 --- a/src/current/_layouts/default.html +++ b/src/current/_layouts/default.html @@ -2,6 +2,7 @@ {% include head.html %} + {% include_cached main-menu-serverless.html %} diff --git a/src/current/js/blockBytedance.js b/src/current/js/blockBytedance.js new file mode 100644 index 00000000000..8283b5500b5 --- /dev/null +++ b/src/current/js/blockBytedance.js @@ -0,0 +1,15 @@ +document.addEventListener('DOMContentLoaded', function() { + var userAgent = navigator.userAgent; + + // Define Bytedance user agents to block + var bytedanceUserAgents = [ + 'Bytespider; spider-feedback@bytedance.com' + ]; + + // Check if the request's user agent matches any of the Bytedance user agents + if (bytedanceUserAgents.some(ua => userAgent.includes(ua))) { + document.write('Access Denied'); + document.close(); + } + }); + \ No newline at end of file From 02083031f1a9ac6c978623e2e10a028aa31ca2ae Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Wed, 24 Jul 2024 19:42:36 +0530 Subject: [PATCH 02/26] implemented edge function --- src/current/_layouts/default.html | 1 - src/current/js/blockBytedance.js | 15 --------------- src/current/netlify.toml | 7 +++++++ .../netlify/edge-functions/blockBytedance.js | 18 ++++++++++++++++++ 4 files changed, 25 insertions(+), 16 deletions(-) delete mode 100644 src/current/js/blockBytedance.js create mode 100644 src/current/netlify/edge-functions/blockBytedance.js diff --git a/src/current/_layouts/default.html b/src/current/_layouts/default.html index 192637056cb..0294f14c0ad 100755 --- a/src/current/_layouts/default.html +++ b/src/current/_layouts/default.html @@ -2,7 +2,6 @@ {% include head.html %} - {% include_cached main-menu-serverless.html %} diff --git a/src/current/js/blockBytedance.js b/src/current/js/blockBytedance.js deleted file mode 100644 index 8283b5500b5..00000000000 --- a/src/current/js/blockBytedance.js +++ /dev/null @@ -1,15 +0,0 @@ -document.addEventListener('DOMContentLoaded', function() { - var userAgent = navigator.userAgent; - - // Define Bytedance user agents to block - var bytedanceUserAgents = [ - 'Bytespider; spider-feedback@bytedance.com' - ]; - - // Check if the request's user agent matches any of the Bytedance user agents - if (bytedanceUserAgents.some(ua => userAgent.includes(ua))) { - document.write('Access Denied'); - document.close(); - } - }); - \ No newline at end of file diff --git a/src/current/netlify.toml b/src/current/netlify.toml index cd8c1c38b45..d7bab24193c 100644 --- a/src/current/netlify.toml +++ b/src/current/netlify.toml @@ -8,6 +8,13 @@ [build.processing.html] pretty_urls = true +[functions] + directory = "netlify/edge-functions" + +[[edge_functions]] + path = "/*" + function = "blockBytedance" + #[[plugins]] # package = "@netlify/plugin-lighthouse" # [plugins.inputs] diff --git a/src/current/netlify/edge-functions/blockBytedance.js b/src/current/netlify/edge-functions/blockBytedance.js new file mode 100644 index 00000000000..06eb355e134 --- /dev/null +++ b/src/current/netlify/edge-functions/blockBytedance.js @@ -0,0 +1,18 @@ +export default async (request) => { + const bytedanceUserAgents = [ + 'Bytespider; spider-feedback@bytedance.com' + ]; + + const userAgent = request.headers.get('user-agent') || ''; + + if (bytedanceUserAgents.some(ua => userAgent.includes(ua))) { + return new Response('Access Denied', { + status: 403, + headers: { + 'Content-Type': 'text/plain' + } + }); + } + + return fetch(request); + }; \ No newline at end of file From e560f46da3debb779095a89f3f021819cb56477b Mon Sep 17 00:00:00 2001 From: ebembi-crdb <169454390+ebembi-crdb@users.noreply.github.com> Date: Wed, 24 Jul 2024 19:59:53 +0530 Subject: [PATCH 03/26] Update netlify.toml --- src/current/netlify.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/current/netlify.toml b/src/current/netlify.toml index d7bab24193c..7a8eb3a9713 100644 --- a/src/current/netlify.toml +++ b/src/current/netlify.toml @@ -14,7 +14,6 @@ [[edge_functions]] path = "/*" function = "blockBytedance" - #[[plugins]] # package = "@netlify/plugin-lighthouse" # [plugins.inputs] From 69ec15aba5a93a3fdc6fefa7c13d19707b587422 Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Wed, 24 Jul 2024 21:24:28 +0530 Subject: [PATCH 04/26] correct netlify directory --- src/current/netlify.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/current/netlify.toml b/src/current/netlify.toml index 7a8eb3a9713..85b40339bf1 100644 --- a/src/current/netlify.toml +++ b/src/current/netlify.toml @@ -9,7 +9,7 @@ pretty_urls = true [functions] - directory = "netlify/edge-functions" + directory = "./netlify/edge-functions" [[edge_functions]] path = "/*" From af7b1d3ba8a5e751630c86af8edb1fb45b260d53 Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Wed, 24 Jul 2024 21:38:25 +0530 Subject: [PATCH 05/26] removed toml variables --- src/current/netlify.toml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/current/netlify.toml b/src/current/netlify.toml index 85b40339bf1..531332475e5 100644 --- a/src/current/netlify.toml +++ b/src/current/netlify.toml @@ -8,12 +8,7 @@ [build.processing.html] pretty_urls = true -[functions] - directory = "./netlify/edge-functions" - -[[edge_functions]] - path = "/*" - function = "blockBytedance" + #[[plugins]] # package = "@netlify/plugin-lighthouse" # [plugins.inputs] From b912b5d5417250315b79771d149ad3679526e84e Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Wed, 24 Jul 2024 21:49:06 +0530 Subject: [PATCH 06/26] testing --- src/current/netlify.toml | 7 +++- .../netlify/edge-functions/blockBytedance.js | 38 ++++++++++--------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/current/netlify.toml b/src/current/netlify.toml index 531332475e5..85b40339bf1 100644 --- a/src/current/netlify.toml +++ b/src/current/netlify.toml @@ -8,7 +8,12 @@ [build.processing.html] pretty_urls = true - +[functions] + directory = "./netlify/edge-functions" + +[[edge_functions]] + path = "/*" + function = "blockBytedance" #[[plugins]] # package = "@netlify/plugin-lighthouse" # [plugins.inputs] diff --git a/src/current/netlify/edge-functions/blockBytedance.js b/src/current/netlify/edge-functions/blockBytedance.js index 06eb355e134..887e2bc9809 100644 --- a/src/current/netlify/edge-functions/blockBytedance.js +++ b/src/current/netlify/edge-functions/blockBytedance.js @@ -1,18 +1,22 @@ export default async (request) => { - const bytedanceUserAgents = [ - 'Bytespider; spider-feedback@bytedance.com' - ]; - - const userAgent = request.headers.get('user-agent') || ''; - - if (bytedanceUserAgents.some(ua => userAgent.includes(ua))) { - return new Response('Access Denied', { - status: 403, - headers: { - 'Content-Type': 'text/plain' - } - }); - } - - return fetch(request); - }; \ No newline at end of file + const bytedanceUserAgents = [ + 'Bytespider; spider-feedback@bytedance.com' + ]; + + const userAgent = request.headers.get('user-agent') || ''; + + if (bytedanceUserAgents.some(ua => userAgent.includes(ua))) { + return new Response('Access Denied', { + status: 403, + headers: { + 'Content-Type': 'text/plain' + } + }); + } + + return fetch(request); +}; + +export const config = { +path: "/*", +}; From 21f2aea10efbc57e61b99af86084d5bcdcae32a5 Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Wed, 24 Jul 2024 21:56:38 +0530 Subject: [PATCH 07/26] removing toml changes --- src/current/netlify.toml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/current/netlify.toml b/src/current/netlify.toml index 85b40339bf1..03ade6dbb75 100644 --- a/src/current/netlify.toml +++ b/src/current/netlify.toml @@ -8,12 +8,7 @@ [build.processing.html] pretty_urls = true -[functions] - directory = "./netlify/edge-functions" -[[edge_functions]] - path = "/*" - function = "blockBytedance" #[[plugins]] # package = "@netlify/plugin-lighthouse" # [plugins.inputs] From d73a8efa106a36adfa73a7e8b311f34b00d8c371 Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Wed, 24 Jul 2024 22:05:03 +0530 Subject: [PATCH 08/26] final changes --- src/current/netlify.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/current/netlify.toml b/src/current/netlify.toml index 03ade6dbb75..cd8c1c38b45 100644 --- a/src/current/netlify.toml +++ b/src/current/netlify.toml @@ -8,7 +8,6 @@ [build.processing.html] pretty_urls = true - #[[plugins]] # package = "@netlify/plugin-lighthouse" # [plugins.inputs] From 1ec815e211c21bd94ef0e2331de61e3aea9283d5 Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Wed, 24 Jul 2024 22:17:46 +0530 Subject: [PATCH 09/26] changes --- .../netlify/edge-functions/blockBytedance.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/current/netlify/edge-functions/blockBytedance.js b/src/current/netlify/edge-functions/blockBytedance.js index 887e2bc9809..9cbfc60e1ad 100644 --- a/src/current/netlify/edge-functions/blockBytedance.js +++ b/src/current/netlify/edge-functions/blockBytedance.js @@ -1,20 +1,24 @@ -export default async (request) => { +export default async (request, context) => { const bytedanceUserAgents = [ 'Bytespider; spider-feedback@bytedance.com' ]; + // Get the user agent from the request headers const userAgent = request.headers.get('user-agent') || ''; - if (bytedanceUserAgents.some(ua => userAgent.includes(ua))) { + // 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' - } + headers: { 'Content-Type': 'text/plain' } }); } - return fetch(request); + // Proceed with the request if it's not a Bytedance user agent + return await context.next(); }; export const config = { From 3e0a6e43fbc5bf76a4f8cbae0d06e823bb1ebef0 Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Wed, 24 Jul 2024 22:18:39 +0530 Subject: [PATCH 10/26] changes --- src/current/netlify.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/current/netlify.toml b/src/current/netlify.toml index cd8c1c38b45..85b40339bf1 100644 --- a/src/current/netlify.toml +++ b/src/current/netlify.toml @@ -8,6 +8,12 @@ [build.processing.html] pretty_urls = true +[functions] + directory = "./netlify/edge-functions" + +[[edge_functions]] + path = "/*" + function = "blockBytedance" #[[plugins]] # package = "@netlify/plugin-lighthouse" # [plugins.inputs] From dfa26bdace5887dbb5223fae67063a001635c3e8 Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Wed, 24 Jul 2024 22:31:59 +0530 Subject: [PATCH 11/26] removed return --- src/current/netlify/edge-functions/blockBytedance.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/current/netlify/edge-functions/blockBytedance.js b/src/current/netlify/edge-functions/blockBytedance.js index 9cbfc60e1ad..60b9fa6ed7c 100644 --- a/src/current/netlify/edge-functions/blockBytedance.js +++ b/src/current/netlify/edge-functions/blockBytedance.js @@ -18,7 +18,7 @@ export default async (request, context) => { } // Proceed with the request if it's not a Bytedance user agent - return await context.next(); + }; export const config = { From 6f62a73059b5a128a788edff41949166e83e96bf Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Wed, 24 Jul 2024 22:42:15 +0530 Subject: [PATCH 12/26] fetch request --- src/current/netlify/edge-functions/blockBytedance.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/current/netlify/edge-functions/blockBytedance.js b/src/current/netlify/edge-functions/blockBytedance.js index 60b9fa6ed7c..4d32a33199b 100644 --- a/src/current/netlify/edge-functions/blockBytedance.js +++ b/src/current/netlify/edge-functions/blockBytedance.js @@ -17,8 +17,9 @@ export default async (request, context) => { }); } - // Proceed with the request if it's not a Bytedance user agent + // Proceed with the request if it's not a Bytedance user agent + return fetch(request); }; export const config = { From 7bb70a682d85c9ebbb986c88bf3dc07ea3b84034 Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Wed, 24 Jul 2024 22:49:50 +0530 Subject: [PATCH 13/26] change toml --- src/current/netlify.toml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/current/netlify.toml b/src/current/netlify.toml index 85b40339bf1..45a34cc1239 100644 --- a/src/current/netlify.toml +++ b/src/current/netlify.toml @@ -2,18 +2,13 @@ base = "src/current/" publish = "_site/" command = "./netlify/build.sh" + edge_functions = "./netlify/edge-functions" [build.environment] NODE_VERSION = "18.14.0" RUBY_VERSION = "3.2.1" [build.processing.html] pretty_urls = true - -[functions] - directory = "./netlify/edge-functions" - -[[edge_functions]] - path = "/*" - function = "blockBytedance" + #[[plugins]] # package = "@netlify/plugin-lighthouse" # [plugins.inputs] From 8105d077f856b9f59414311b86da0b1856427591 Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Wed, 24 Jul 2024 22:56:22 +0530 Subject: [PATCH 14/26] testing --- src/current/netlify/edge-functions/blockBytedance.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/current/netlify/edge-functions/blockBytedance.js b/src/current/netlify/edge-functions/blockBytedance.js index 4d32a33199b..58297c4a93b 100644 --- a/src/current/netlify/edge-functions/blockBytedance.js +++ b/src/current/netlify/edge-functions/blockBytedance.js @@ -19,7 +19,9 @@ export default async (request, context) => { // Proceed with the request if it's not a Bytedance user agent - return fetch(request); + return new Response(`Hello there! You can freely access our content from ${countryName}!`, { + headers: { 'Content-Type': 'text/html' } + }); }; export const config = { From 5b1c32c443ebe74ff82f9295522dacbd14c96be1 Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Wed, 24 Jul 2024 22:59:42 +0530 Subject: [PATCH 15/26] testing --- src/current/netlify/edge-functions/blockBytedance.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/current/netlify/edge-functions/blockBytedance.js b/src/current/netlify/edge-functions/blockBytedance.js index 58297c4a93b..ad3683a3ba4 100644 --- a/src/current/netlify/edge-functions/blockBytedance.js +++ b/src/current/netlify/edge-functions/blockBytedance.js @@ -19,9 +19,10 @@ export default async (request, context) => { // Proceed with the request if it's not a Bytedance user agent - return new Response(`Hello there! You can freely access our content from ${countryName}!`, { - headers: { 'Content-Type': 'text/html' } - }); + const url = new URL(request.url); + url.pathname = '/'; // Redirect to the root directory + return Response.redirect(url.toString(), 302); // 302 status for temporary redirect + }; export const config = { From 88339acd6fdcf524a33dcc553b9066598f625d78 Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Wed, 24 Jul 2024 23:11:15 +0530 Subject: [PATCH 16/26] test --- .../netlify/edge-functions/blockBytedance.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/current/netlify/edge-functions/blockBytedance.js b/src/current/netlify/edge-functions/blockBytedance.js index ad3683a3ba4..12317eacd0b 100644 --- a/src/current/netlify/edge-functions/blockBytedance.js +++ b/src/current/netlify/edge-functions/blockBytedance.js @@ -1,4 +1,4 @@ -export default async (request, context) => { +export default async (request) => { const bytedanceUserAgents = [ 'Bytespider; spider-feedback@bytedance.com' ]; @@ -17,14 +17,20 @@ export default async (request, context) => { }); } - - // Proceed with the request if it's not a Bytedance user agent + // Avoid redirecting if already at the root directory const url = new URL(request.url); + if (url.pathname === '/') { + // Serve the root directory content or a custom message + return new Response('

Welcome to the root directory!

', { + headers: { 'Content-Type': 'text/html' } + }); + } + + // Redirect to the root directory for all other requests url.pathname = '/'; // Redirect to the root directory return Response.redirect(url.toString(), 302); // 302 status for temporary redirect - }; export const config = { -path: "/*", + path: "/*", }; From 9aa5c66e6f9e712054a32454a039f41445f9bcab Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Wed, 24 Jul 2024 23:25:42 +0530 Subject: [PATCH 17/26] test --- .../netlify/edge-functions/blockBytedance.js | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/current/netlify/edge-functions/blockBytedance.js b/src/current/netlify/edge-functions/blockBytedance.js index 12317eacd0b..de581978c2f 100644 --- a/src/current/netlify/edge-functions/blockBytedance.js +++ b/src/current/netlify/edge-functions/blockBytedance.js @@ -17,18 +17,7 @@ export default async (request) => { }); } - // Avoid redirecting if already at the root directory - const url = new URL(request.url); - if (url.pathname === '/') { - // Serve the root directory content or a custom message - return new Response('

Welcome to the root directory!

', { - headers: { 'Content-Type': 'text/html' } - }); - } - - // Redirect to the root directory for all other requests - url.pathname = '/'; // Redirect to the root directory - return Response.redirect(url.toString(), 302); // 302 status for temporary redirect + return fetch(request); }; export const config = { From f3118e480fcba64b51d97b6d4d1c98c378b4d4ff Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Wed, 24 Jul 2024 23:32:33 +0530 Subject: [PATCH 18/26] test --- src/current/netlify.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/current/netlify.toml b/src/current/netlify.toml index 45a34cc1239..7b8042f98be 100644 --- a/src/current/netlify.toml +++ b/src/current/netlify.toml @@ -8,6 +8,10 @@ RUBY_VERSION = "3.2.1" [build.processing.html] pretty_urls = true + +[[edge_functions]] + path = "/*" + function = "blockBytedance" #[[plugins]] # package = "@netlify/plugin-lighthouse" From b78c77312df18b8b82c20e0535d341756af5e1aa Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Wed, 24 Jul 2024 23:52:38 +0530 Subject: [PATCH 19/26] test --- src/current/netlify.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/current/netlify.toml b/src/current/netlify.toml index 7b8042f98be..a832f7b16fa 100644 --- a/src/current/netlify.toml +++ b/src/current/netlify.toml @@ -2,7 +2,6 @@ base = "src/current/" publish = "_site/" command = "./netlify/build.sh" - edge_functions = "./netlify/edge-functions" [build.environment] NODE_VERSION = "18.14.0" RUBY_VERSION = "3.2.1" From aab4dbdbf2c71cece4110bc23048e95dd74b1fa7 Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Thu, 25 Jul 2024 00:00:34 +0530 Subject: [PATCH 20/26] test --- src/current/netlify/edge-functions/blockBytedance.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/current/netlify/edge-functions/blockBytedance.js b/src/current/netlify/edge-functions/blockBytedance.js index de581978c2f..0b25e9033e2 100644 --- a/src/current/netlify/edge-functions/blockBytedance.js +++ b/src/current/netlify/edge-functions/blockBytedance.js @@ -20,6 +20,4 @@ export default async (request) => { return fetch(request); }; -export const config = { - path: "/*", -}; + From 33f68601d484112092a2f1a6e584f80d79622dc5 Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Thu, 25 Jul 2024 00:05:27 +0530 Subject: [PATCH 21/26] testing --- src/current/netlify/edge-functions/blockBytedance.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/current/netlify/edge-functions/blockBytedance.js b/src/current/netlify/edge-functions/blockBytedance.js index 0b25e9033e2..dd733a0e41b 100644 --- a/src/current/netlify/edge-functions/blockBytedance.js +++ b/src/current/netlify/edge-functions/blockBytedance.js @@ -17,7 +17,14 @@ export default async (request) => { }); } - return fetch(request); + console.log(`Request URL: ${url.href}`); + + // Process and forward the request + const response = await fetch(request); + console.log(`Response Status: ${response.status}`); + + return response; + }; From c39dab434cdc3b10db5e19038f96b124809398b7 Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Thu, 25 Jul 2024 00:13:37 +0530 Subject: [PATCH 22/26] test --- src/current/netlify/edge-functions/blockBytedance.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/current/netlify/edge-functions/blockBytedance.js b/src/current/netlify/edge-functions/blockBytedance.js index dd733a0e41b..08738ef7b38 100644 --- a/src/current/netlify/edge-functions/blockBytedance.js +++ b/src/current/netlify/edge-functions/blockBytedance.js @@ -26,5 +26,8 @@ export default async (request) => { return response; }; +export const config = { + path: "/*", +}; From 56e2cfd759845f8fecaa2576f0b0777e7ce9cfd1 Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Thu, 25 Jul 2024 00:21:28 +0530 Subject: [PATCH 23/26] test --- src/current/netlify.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/current/netlify.toml b/src/current/netlify.toml index a832f7b16fa..7b8042f98be 100644 --- a/src/current/netlify.toml +++ b/src/current/netlify.toml @@ -2,6 +2,7 @@ base = "src/current/" publish = "_site/" command = "./netlify/build.sh" + edge_functions = "./netlify/edge-functions" [build.environment] NODE_VERSION = "18.14.0" RUBY_VERSION = "3.2.1" From 1944f3ae5fcc1c2f0aa59cffaa4afbf40f2534ef Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Thu, 25 Jul 2024 00:29:50 +0530 Subject: [PATCH 24/26] test --- .../netlify/edge-functions/blockBytedance.js | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/current/netlify/edge-functions/blockBytedance.js b/src/current/netlify/edge-functions/blockBytedance.js index 08738ef7b38..d2fc5a0a97b 100644 --- a/src/current/netlify/edge-functions/blockBytedance.js +++ b/src/current/netlify/edge-functions/blockBytedance.js @@ -1,6 +1,9 @@ -export default async (request) => { +import { Context } from 'https://edge.netlify.com' + +export default async function handler(request) { const bytedanceUserAgents = [ 'Bytespider; spider-feedback@bytedance.com' + // Add other Bytedance user agents if needed ]; // Get the user agent from the request headers @@ -16,18 +19,10 @@ export default async (request) => { headers: { 'Content-Type': 'text/plain' } }); } + + return fetch(request); +} - console.log(`Request URL: ${url.href}`); - - // Process and forward the request - const response = await fetch(request); - console.log(`Response Status: ${response.status}`); - - return response; - -}; export const config = { path: "/*", -}; - - +}; \ No newline at end of file From 0b314b48dd405c2d16658ca7f5067313af8612d4 Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Thu, 25 Jul 2024 00:44:13 +0530 Subject: [PATCH 25/26] test --- src/current/netlify/edge-functions/blockBytedance.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/current/netlify/edge-functions/blockBytedance.js b/src/current/netlify/edge-functions/blockBytedance.js index d2fc5a0a97b..4809e17ba54 100644 --- a/src/current/netlify/edge-functions/blockBytedance.js +++ b/src/current/netlify/edge-functions/blockBytedance.js @@ -1,4 +1,3 @@ -import { Context } from 'https://edge.netlify.com' export default async function handler(request) { const bytedanceUserAgents = [ @@ -19,7 +18,6 @@ export default async function handler(request) { headers: { 'Content-Type': 'text/plain' } }); } - return fetch(request); } From 2b791190b4e7fc1dfa232b45c95da0533830de57 Mon Sep 17 00:00:00 2001 From: ebembi-crdb Date: Thu, 25 Jul 2024 01:09:22 +0530 Subject: [PATCH 26/26] test --- .../{blockBytedance.js => blockBytedance.ts} | 16 +++++++++++----- src/current/package.json | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) rename src/current/netlify/edge-functions/{blockBytedance.js => blockBytedance.ts} (56%) diff --git a/src/current/netlify/edge-functions/blockBytedance.js b/src/current/netlify/edge-functions/blockBytedance.ts similarity index 56% rename from src/current/netlify/edge-functions/blockBytedance.js rename to src/current/netlify/edge-functions/blockBytedance.ts index 4809e17ba54..48798656749 100644 --- a/src/current/netlify/edge-functions/blockBytedance.js +++ b/src/current/netlify/edge-functions/blockBytedance.ts @@ -1,5 +1,6 @@ +import type { Config, Context } from "@netlify/edge-functions"; -export default async function handler(request) { +export default async function handler(request: Request, context: Context) { const bytedanceUserAgents = [ 'Bytespider; spider-feedback@bytedance.com' // Add other Bytedance user agents if needed @@ -18,9 +19,14 @@ export default async function handler(request) { headers: { 'Content-Type': 'text/plain' } }); } - return fetch(request); + + // 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 = { - path: "/*", -}; \ No newline at end of file +export const config: Config = { + path: "/*", // This path can be adjusted based on where you want to apply this edge function +}; diff --git a/src/current/package.json b/src/current/package.json index c5f19f72dcc..00cd1d13d42 100644 --- a/src/current/package.json +++ b/src/current/package.json @@ -7,6 +7,7 @@ "jest-cli": "^26" }, "dependencies": { + "@netlify/edge-functions": "^2.10.0", "front-matter": "^4.0.2", "redoc-cli": "^0.11.4", "snippet-enricher-cli": "^0.0.8",