Call worker from pages
I have a really simple website (remix) built and deployed with pages. I have contact form that when submitted sends an email. Currently I have it setup so that there is a worker running on different domain, and when the form is submitted my action function makes a request to the other domain and the worker on that domain sends the message.
My question is, is there a way to call email send script/worker directly such that it can all be hosted on a single domain. I would set up all the required bindings and so on. Basically, can I call my
mailer.js
script from inside a remix function?3 Replies
mailer.js
is basically the same as shown in the docs here:
https://developers.cloudflare.com/email-routing/email-workers/send-email-workers/Cloudflare Docs
Send emails from Workers · Cloudflare Email Routing docs
You can send an email about your Worker’s activity from your Worker to an email address verified on Email Routing. This is useful for when you want to …
Is there a reason you can’t just add this code the pages function? I know with worker to worker you can call each other in code, but I’m not sure about pages to worker.
One issue I'm having is that I can't add the
send_email
binding to the wrangler.toml
, without that I doubt it will work, and thus I haven'tried.
The other option I see in the docs is to use a service binding but again not sure on how to implement.