lokiwind
lokiwind
CDCloudflare Developers
Created by lokiwind on 7/5/2023 in #workers-help
Creating worker with api
19 replies
CDCloudflare Developers
Created by lokiwind on 6/5/2023 in #general-help
Wordpress directly url rule.
1 replies
CDCloudflare Developers
Created by lokiwind on 6/3/2023 in #general-help
Rate limit does not egual path
7 replies
CDCloudflare Developers
Created by lokiwind on 6/2/2023 in #workers-help
Listing Firewall Events..
I am listing Cloudflare firewall events. However, instead of writing which rule is in the source section, it says firewallCustom. How can i fix this... My code: https://discord.com/channels/595317990191398933/1114130327351332964 Source eq: Http 1.0 Block Rule...
{
"events": [
{
"action": "skip",
"clientAsn": "8075",
"clientCountryName": "US",
"clientIP": "52.167.144.131",
"clientRequestPath": "/robots.txt",
"clientRequestQuery": "",
"datetime": "2023-06-02T19:40:40Z",
"source": "firewallCustom",
"userAgent": "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm) Chrome/103.0.5060.134 Safari/537.36"
}
]
}
{
"events": [
{
"action": "skip",
"clientAsn": "8075",
"clientCountryName": "US",
"clientIP": "52.167.144.131",
"clientRequestPath": "/robots.txt",
"clientRequestQuery": "",
"datetime": "2023-06-02T19:40:40Z",
"source": "firewallCustom",
"userAgent": "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm) Chrome/103.0.5060.134 Safari/537.36"
}
]
}
25 replies
CDCloudflare Developers
Created by lokiwind on 5/26/2023 in #workers-help
workers txt reading and writing
8 replies
CDCloudflare Developers
Created by lokiwind on 5/25/2023 in #workers-help
Listing more than 1k KV keys
Hello, can this code list more than 1k data that I saved to KV storage at the same time? NOTE:The code currently lists the data without problems, but I wondered if it lists all data when there is more than 1k data
export default {
async fetch(request, env, ctx) {
const keys = new Set();
let cursor = undefined;

async function gatherKeys() {
while (true) {
const result = await env.LOG_IP.list({ cursor });
for (const { name } of result.keys) {
keys.add(name);
}
if (result.list_complete) {
break;
}
cursor = result.cursor;
}
}

await gatherKeys();

const keysArray = Array.from(keys.values());
const keysText = keysArray.join('\n');

return new Response(keysText, {
status: 200,
headers: { 'Content-Type': 'text/plain' },
});
},
};

export default {
async fetch(request, env, ctx) {
const keys = new Set();
let cursor = undefined;

async function gatherKeys() {
while (true) {
const result = await env.LOG_IP.list({ cursor });
for (const { name } of result.keys) {
keys.add(name);
}
if (result.list_complete) {
break;
}
cursor = result.cursor;
}
}

await gatherKeys();

const keysArray = Array.from(keys.values());
const keysText = keysArray.join('\n');

return new Response(keysText, {
status: 200,
headers: { 'Content-Type': 'text/plain' },
});
},
};

3 replies
CDCloudflare Developers
Created by lokiwind on 5/24/2023 in #workers-help
Problem saving data 2 times in 1 request
18 replies
CDCloudflare Developers
Created by lokiwind on 4/11/2023 in #workers-help
2 return fetch request
Hello, I am using this workers code in front of my website, but when I use "return fetch(request);" instead of the return "fetch(url, init);" parameter in line 24, the post operation does not occur. How can I replace "fetch(url, init);" with "return fetch(request);".. addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)) }) async function handleRequest(request) { const ip = request.headers.get("CF-Connecting-IP"); const countryCode = request.headers.get("CF-IPCountry"); const response = await fetch("https://mypage.xx/ip.txt"); const text = await response.text(); const ipInfo = text.trim().split('\n').find(line => line.startsWith(ip)); if (ipInfo) { return fetch(request); } const url = "https://mypage.xx/public.php"; const data = new URLSearchParams({ "data": ${ip}|${countryCode} }); const init = { method: "POST", body: data }; return fetch(url, init); }
2 replies