ShaharMS
ShaharMS
CDCloudflare Developers
Created by ShaharMS on 8/20/2024 in #pages-help
Run a nodejs script right before website is deployed to transform the website's content
my website is multilingual, and i do it by running a script on my project that transforms it into multiple folders, each for a different language. I run that script during development to view my website, but is there a way to do that in cloudflare?
17 replies
CDCloudflare Developers
Created by ShaharMS on 7/30/2023 in #workers-help
env.KV_NAMESPACE.put(...) never actually writes anything
i might be dong this icorrectly, if so, please tell me: i connected the KV to my worker in the toml file. that also shows up on cloudflare's website. whenever the user sends json data, it should get written:
const requestData = await request.json()
currentUsername = requestData.name;
if (acceptedNames.includes(requestData.name)) {
acceptedEntry = true;
var m = new Map();
for (let i = 0; i < requestData.array.length; i += 2) {
m[requestData.array[i]] = requestData.array[i + 1];
}
env.GROUP_CAL.put(requestData.name, m);
groupCal.set(requestData.name, m);
} else acceptedEntry = false;
const requestData = await request.json()
currentUsername = requestData.name;
if (acceptedNames.includes(requestData.name)) {
acceptedEntry = true;
var m = new Map();
for (let i = 0; i < requestData.array.length; i += 2) {
m[requestData.array[i]] = requestData.array[i + 1];
}
env.GROUP_CAL.put(requestData.name, m);
groupCal.set(requestData.name, m);
} else acceptedEntry = false;
even though requestData is defined, and groupCal gets written to, it seems like GROUP_CAL isnt getting written to, since when returning the new site (or even retrieving it a couple minutes after the put), and writing from GROUP_CAL to groupCal, the result is always {}:
for (const name of acceptedNames) {
let val = await env.GROUP_CAL.get(name);
if (val !== null) {
groupCal[name] = val;
} else console.log(name + " has no data.");
}
for (const name of acceptedNames) {
let val = await env.GROUP_CAL.get(name);
if (val !== null) {
groupCal[name] = val;
} else console.log(name + " has no data.");
}
what am i doing wrong?
25 replies
CDCloudflare Developers
Created by ShaharMS on 7/30/2023 in #workers-help
How do i create a working wrangler.toml file from quickedit?
I'm using cloudflare workers, and im editing my worker with cloudflare's Quick Edit. when just using env.MY_KV_NAMESPACE, couldnt get the values in it, so i figured i should create a wrangler.toml file. when i do create one, and put the 3 required fields, along with the kv namespace, it doesnt work, and sends error:
Script modified; context reset
Script modified; context reset
what am i doing wrong? if im creating the file wrong, how do i do it correctly from quickedit?
4 replies