Workers for platforms authentication

How are users authenticated when using Workers for Platforms? Does each user need their own CloudFlare account or is is possible to support deployment on their behalf?
11 Replies
Hello, I’m Allie!
WfP Workers are deployed on your account. They do not require an account for each customer
avaer
avaerOP7mo ago
I see, so how would a user deploy a worker in that case? Does the user run Wrangler, or would we run wrangler on their code on their behalf? Wrangler requires a login so the user would need an account if they are running it. Also I wasn't able to find a programmatic interface to wrangler (outside of the CLI), so it's hard to e.g. create a cf worker that will provide a deployment interface, since it's hard to run wrangler inside a worker (not to mention you'd need a virtual FS to do this). Any advice as to best practices? thanks!
Hello, I’m Allie!
Your application would take the user Worker, then upload to WfP via the API
avaer
avaerOP7mo ago
thanks, unfortunately the API crashes for me (opaque internal error on the CF side). I have a ticket open for about 2 weeks now. I was looking for a way to fast track it without having to deal with cloudflare crashing on the backend.
Hello, I’m Allie!
What’s the ticket ID?
Walshy
Walshy7mo ago
Looking
module worker.js.map has unsupported Content-Type application/json
Not sure why this is returning internal error - i'll look into that but yeah, you're uploading a source map and that isn't supported
avaer
avaerOP7mo ago
ok that's useful info, thanks so removing the source map worked, but now I'm getting a synax error on export
{
"result": null,
"success": false,
"errors": [
{
"code": 10021,
"message": "Uncaught SyntaxError: Unexpected token 'export'\n at worker.mjs:56051\n"
}
],
"messages": []
}
{
"result": null,
"success": false,
"errors": [
{
"code": 10021,
"message": "Uncaught SyntaxError: Unexpected token 'export'\n at worker.mjs:56051\n"
}
],
"messages": []
}
avaer
avaerOP7mo ago
I'm building the code with wrangler build and then uploading the resulting JS file (which is ESM) with the mapping set for ESM per https://developers.cloudflare.com/api/operations/worker-script-put-content
Cloudflare API Documentation
Interact with Cloudflare's products and services via the Cloudflare API
avaer
avaerOP7mo ago
I tried using both/either CF-WORKER-MAIN-MODULE-PART and the metadata JSON field main_module in the FormData
const form = new FormData();
form.append('worker.mjs', Buffer.from(mainJsString, 'utf8'), {
filename: 'worker.mjs',
filepath: 'worker.mjs',
contentType: 'application/javascript',
});
form.append(
'metadata',
Buffer.from(
JSON.stringify({
main_module: 'worker.mjs',
}),
'utf8',
),
);
const form = new FormData();
form.append('worker.mjs', Buffer.from(mainJsString, 'utf8'), {
filename: 'worker.mjs',
filepath: 'worker.mjs',
contentType: 'application/javascript',
});
form.append(
'metadata',
Buffer.from(
JSON.stringify({
main_module: 'worker.mjs',
}),
'utf8',
),
);
presumably this should allow the worker to be detected as ESM and therefore export shouldn't be a syntax error but the backend tells me it is (also note that the documentation says that source maps are supported, Source maps may also be included using the application/source-map content type., which is why I was confused why that causes the crash. I uploaded the built worker file to the ticket as well
Walshy
Walshy7mo ago
you're trying to upload as a service worker not esmodule worker -- content type for it should be application/javascript+module and you'll want to use main_module in metadata yeah (sorry i wish this api was easier but we need to support so much stuff it gets complex) (fwiw if you can use wrangler wrangler deploy --dispatch-namespace <your-namespace> works)
Want results from more Discord servers?
Add your server