Dahoom4030
Dahoom4030
CDCloudflare Developers
Created by Dahoom4030 on 1/22/2024 in #pages-help
Is it possible to disable generation of _worker.js.map in sveltekit?
No description
1 replies
CDCloudflare Developers
Created by Dahoom4030 on 8/8/2023 in #workers-help
request.cf.botManagement.score not working
request.cf.botManagement.score not working after building from ts? I dont use ts much so i have no idea why this is happening:
`"exceptions": [
{
"name": "TypeError",
"message": "Cannot read properties of undefined (reading 'score')",
"timestamp": 1691488611986
}
],

`"exceptions": [
{
"name": "TypeError",
"message": "Cannot read properties of undefined (reading 'score')",
"timestamp": 1691488611986
}
],

I tried it again in vanilla and it does not work there either, I had it working yesterday and got the 99 score, I'm unsure what changed today to make it non functional
export default {
async fetch(request, env, ctx) {
return new Response(`score: ${request.cf.botManagement.score}`);
},
};
export default {
async fetch(request, env, ctx) {
return new Response(`score: ${request.cf.botManagement.score}`);
},
};
7 replies
CDCloudflare Developers
Created by Dahoom4030 on 8/5/2023 in #workers-help
Does anyone know how to get accurate country/city data?
I've been attempting to use request.cf.country but sometimes it returns XX, and cities empty, despite having valid LAT, LONG values which can be used to find the correct location. I am using a vpn when testing other locations but I'm confusesd as to how the LAT,LONG values are correct but are not able to be geolocated in the other headers. Testing it again i see that the LAT,LONG values are incorrect but I am able to get the correct location from getting the Geolocation of the IP from
request.headers.get('CF-Connecting-IP')
request.headers.get('CF-Connecting-IP')
How do i get accruate country/city data? I don't want to use maxMind if there's a workers/cloudflare trasnform feature that I'm missing.
4 replies
CDCloudflare Developers
Created by Dahoom4030 on 5/9/2023 in #workers-help
Unable to load tfjs ML model
Hello guys, I'm having a bit of a problem with trying to get tensorflow.js working on cloudflare workers. When loading tf.loadLayersModel() it starts 45 concurrent connections to read all my binary files which are currently stored on r2. This causes "Error: Response closed due to connection limit". I've tried to use the R2 env variable but the function requires a url to be passed into it so it can load the main file (model.json) and the dozens of other binary files contained in the same folder. I've attempted to read them 1 by 1 but at that point the worker timed out barely getting past 35. I've attempted to store them into KV but they are binary files and it seems like i wasnt able to insert them into KV as is. I was thinking of converting the binary into a base64 string to be able to store but that just added another layer of processing which i have no cpu time left for. TLDR Im looking for the concurrent connection limit for r2 to read multiple files in the same folder at the same time, and I'm wondering if its possible to increase the limit somehow or limit it to a couple of concurrent at a time but i have no idea what the limit is. I'm sure combining them would fix the issue but I'm scared I would spend hours on it and get no return after hitting another wall. Is there some other worker function? This is the test code I'm currently using:
import * as tf from '@tensorflow/tfjs';

async function loadModel() {
const model = await tf.loadLayersModel('https://custom(r2).domain/models/tfjs_model/model.json');
return model;
}

addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event));
});

async function handleRequest(event) {
try {
const model = await loadModel();
console.log('Model loaded successfully');
return new Response('Model loaded successfully', { status: 200 });
} catch (err) {
console.error('An error occurred:', err);
return new Response('An error occurred:'+err, { status: 500 });
}
}
import * as tf from '@tensorflow/tfjs';

async function loadModel() {
const model = await tf.loadLayersModel('https://custom(r2).domain/models/tfjs_model/model.json');
return model;
}

addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event));
});

async function handleRequest(event) {
try {
const model = await loadModel();
console.log('Model loaded successfully');
return new Response('Model loaded successfully', { status: 200 });
} catch (err) {
console.error('An error occurred:', err);
return new Response('An error occurred:'+err, { status: 500 });
}
}
1 replies