#Initializing

36 messages · Page 1 of 1 (latest)

uncut sparrow
#

My worker is stuck on Initializing workers.dev subdomain... is that due to the outages

leaden dome
uncut sparrow
leaden dome
#

If it's not causing issues, I would just advert your eyes from it for now, should go away when the incident is over

#

By "access it", you mean actually trigger the worker right? If it doesn't show you the url, it'd just be <worker-name>.yoursubdomain (shown in overview).workers.dev

uncut sparrow
#

I mean I can access its settings. The worker domain is inaccessable

leaden dome
#

ah ok, yea this is def related to the outage, interesting though. Is this the first worker on your account or something? I can seem to create new ones fine on my end

uncut sparrow
#

My first worker yes

leaden dome
#

It's gotta do some setup then for your worker.dev domain I imagine. You could try adding a worker custom domain on one of your domains (if you have any in Cloudflare & if you can access it that menu under Triggers of the Worker), otherwise you'll probably just need to wait it out

uncut sparrow
#

Its fairly basic I want a URL that I can give a ?code=somestring query and it will make a POST request to a different url with the body as {"content":somestring}

leaden dome
uncut sparrow
#

Any alternatives that can achieve that?

leaden dome
#

Converting a query string to a POST Request on a different url? Only Workers would be dynamic enough to do anything like that

#

If you want to add this over an existing web server/origin, you could try adding the http route for it, it sounds like to me it's just the workers.dev domain having issues and not the worker itself

uncut sparrow
#

Basically a GET request to the worker or whatever service url.com?code=MyString
A POST request to another URL with body={"content":MyString}

leaden dome
#

The only Cloudflare product that can really do dynamic stuff like that would be Workers

#

You have the right answer to your question, just need to wait for service to be restored, or try adding a custom domain/route to the Worker to try to get around the worker.dev issues

uncut sparrow
#

Sorry I forgot to turn off ping

#

And for some reason it says my worker has 71 requests

#

The error message is:
Cannot read properties of undefined (reading 'webhook')
I have a secret called webhook

#

Im getting it with event.env.webhook

leaden dome
leaden dome
# uncut sparrow Im getting it with event.env.webhook

what's your code look like? If you're using module workers, you'd just grab env off the request. If old service workers with addEventListener, then they're just globals. event sounds like either a framework or something else

uncut sparrow
#
addEventListener('fetch', event => {
  event.respondWith(eventHandler(event));
});
async function eventHandler(event) {
const env = event.env;```
leaden dome
#

there's no env on event with addEventListener/service workers

#

environment variables are just globals

uncut sparrow
#

So how do I get it?

leaden dome
#

If you named it webhook, would just be webhook or globalThis.webhook

leaden dome
# uncut sparrow thanks

no problem, if you can, I would consider migrating and using Module Format instead of Service Worker format/addEventListener:
https://developers.cloudflare.com/workers/learning/migrate-to-module-workers/
Service Worker Format does not/will not support all future features and bindings, and it's slower and more messy

For example, with module workers, that'd be like this:

export default {
  async fetch(request, env, ctx) {
    return new Response(env.webhook);
  },
};

Write your Worker code in ES modules syntax for an optimized experience.

#

no rush though, the guarantee with Workers is that old code will always keep running thanks to compatibility dates and such, not going to have service worker format workers stop working one day

uncut sparrow
leaden dome
#

The online editor is a bit silly and tries to autosuggest this.fetch() on autocomplete, make sure you're not doing that

#

just bare fetch() is what you need