TechParadox
TechParadox
CDCloudflare Developers
Created by TechParadox on 8/17/2024 in #workers-help
Dynamic require of "cloudflare:workers" is not supported
I'm trying to create a cloudflare worker that is accessed via services by another worker. I followed the example here https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/ The worker fails to deploy with the error in the title. I aslo get this warning: ▲ [WARNING] The entrypoint src/gemini.ts has exports like an ES Module, but hasn't defined a default export like a module worker normally would. Building the worker using "service-worker" format... Service Worker wrangler toml:
name = "iai-gemini"
main = "src/gemini.ts"
compatibility_date = "2024-08-06"
compatibility_flags = ["nodejs_compat"]
name = "iai-gemini"
main = "src/gemini.ts"
compatibility_date = "2024-08-06"
compatibility_flags = ["nodejs_compat"]
Service worker code (too long for discord) https://pastebin.com/VraghKaZ
7 replies
CDCloudflare Developers
Created by TechParadox on 8/11/2024 in #general-help
Sending email via workers with mailjet API
The mailjet api provides curl command:
curl -s \
-X POST \
--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
https://api.mailjet.com/v3.1/send \
-H 'Content-Type: application/json' \
-d '{
"SandboxMode":"true",
"Messages":[
{
"From":[
{
"Email":"[email protected]",
"Name":"Your Mailjet Pilot"
}
],
"HTMLPart":"<h3>Dear passenger, welcome to Mailjet!</h3><br />May the delivery force be with you!",
"Subject":"Your email flight plan!",
"TextPart":"Dear passenger, welcome to Mailjet! May the delivery force be with you!",
"To":[
{
"Email":"[email protected]",
"Name":"Passenger 1"
}
]
}
]
}'
curl -s \
-X POST \
--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
https://api.mailjet.com/v3.1/send \
-H 'Content-Type: application/json' \
-d '{
"SandboxMode":"true",
"Messages":[
{
"From":[
{
"Email":"[email protected]",
"Name":"Your Mailjet Pilot"
}
],
"HTMLPart":"<h3>Dear passenger, welcome to Mailjet!</h3><br />May the delivery force be with you!",
"Subject":"Your email flight plan!",
"TextPart":"Dear passenger, welcome to Mailjet! May the delivery force be with you!",
"To":[
{
"Email":"[email protected]",
"Name":"Passenger 1"
}
]
}
]
}'
This is what I'm trying to do in my worker:
async function sendEmailOrLog(env: Bindings, username: string, recipient: string, sender_pre_at: string, subject: string, content: string) {
// Prepare email
const response = await fetch('https://api.mailjet.com/v3.1/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Basic ' + btoa(`${env.MAILJET_API_KEY}:${env.MAIILJET_SECRET_KEY}`),
},
body: JSON.stringify({
SandboxMode: 'false',
Messages: [
{
From: [
{
Email: `${sender_pre_at.toLowerCase()}@instructor-ai.com`,
Name: `Instructor-AI`,
},
],
HTMLPart: `<h3>${content}</h3>`,
Subject: subject,
TextPart: content,
To: [
{
Email: recipient,
Name: username,
async function sendEmailOrLog(env: Bindings, username: string, recipient: string, sender_pre_at: string, subject: string, content: string) {
// Prepare email
const response = await fetch('https://api.mailjet.com/v3.1/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Basic ' + btoa(`${env.MAILJET_API_KEY}:${env.MAIILJET_SECRET_KEY}`),
},
body: JSON.stringify({
SandboxMode: 'false',
Messages: [
{
From: [
{
Email: `${sender_pre_at.toLowerCase()}@instructor-ai.com`,
Name: `Instructor-AI`,
},
],
HTMLPart: `<h3>${content}</h3>`,
Subject: subject,
TextPart: content,
To: [
{
Email: recipient,
Name: username,
Am I doing something wrong? I get 400 error
5 replies
CDCloudflare Developers
Created by TechParadox on 8/11/2024 in #general-help
Having trouble getting session cookie to store (lucia-auth, hono, cloudflare pages/worker)
My worker is hosted at api.domain.com and my frontend is using domain.com When I post to api.domain.com/users from domain.com the response header shows the session cookie. It then redirects to domain.com/email-verification, but the cookie is not stored in the browser. What am I doing wrong? Any assistance is greatly appreciated. Code (I removed some stuff to save space) https://pastebin.com/70cy8PzV
4 replies