Uploading worker module with the TS SDK

Is there a code snippet or something for creating a worker with the TS SDK? https://developers.cloudflare.com/api/node/resources/workers/subresources/scripts/methods/update/ I think im struggling to read the doc so i think a code snippet would help me figure out how to use it. I've got an implementation with just fetch() but i'd much prefer the type safety of the sdk when possible. I seem to just get this error Failed to deploy Cloudflare Worker: Error: 400 {"result":null,"success":false,"errors":[{"code":10021,"message":"No event handlers were registered. This script does nothing.\n"}],"messages":[]}
const form = new FormData();

form.append("worker.js",
new File([workerScript], "worker.js", {
type: "application/javascript+module",
}),
);

const client = new Cloudflare({
apiToken: env.CLOUDFLARE_API_TOKEN,
});

const response = await client.workers.scripts.update(workerName, {
account_id: env.CLOUDFLARE_ACCOUNT_ID,
metadata: {
main_module: "worker.js",
bindings: [],
body_part: "worker.js",
},
},
{
body: form,
},
);
const form = new FormData();

form.append("worker.js",
new File([workerScript], "worker.js", {
type: "application/javascript+module",
}),
);

const client = new Cloudflare({
apiToken: env.CLOUDFLARE_API_TOKEN,
});

const response = await client.workers.scripts.update(workerName, {
account_id: env.CLOUDFLARE_ACCOUNT_ID,
metadata: {
main_module: "worker.js",
bindings: [],
body_part: "worker.js",
},
},
{
body: form,
},
);
Cloudflare API | Workers › Scripts › update
Interact with Cloudflare's products and services via the Cloudflare API
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?