mattp
04/14/2023, 8:49 AMitty-router
for routing
typescript
export default {
fetch: async (request: Request, env: Env, context: Context) => {
context.slack = new Slack(env.SLACK_APP_BOT_TOKEN);
context.waitUntil(router.handle(request, env, context));
},
};
duplex
04/14/2023, 11:46 AMapi.example.com/path-a/*
-> worker-a
2. api.example.com/path-b/*
-> worker-b
3. api.example.com/path-c*
-> worker-c
Every worker has a following setting in `worker.toml`:
[env.production]
name = "worker-a"
route = { pattern = "api.example.com/path-a/*", zone_name = "example.com" }
I fail to access these workers over HTTP. Looks like I'm missing something, help me out duplex
04/14/2023, 1:06 PM[[env.production.services]]
binding = "workerA"
service = "worker-a"
[[env.production.services]]
binding = "workerB"
service = "worker-b"
Both services are called like that:
const workerAResponse = await env.workerA.fetch(
new Request(new URL(`worker-a/${id}`, env.WORKER_A_DOMAIN)),
{
headers: request.clone().headers,
}
);
if (!workerAResponse.ok) { return workerAResponse }
const { public_id } = await workerAResponse.json();
const workerBResponse = await env.workerB.fetch(
new Request(new URL(`worker-b/${public_id}`, env.WORKER_B_DOMAIN)),
{
headers: request.clone().headers,
}
);
if (!workerBResponse.ok) { return workerBResponse; }
Request to worker-a
is successful, however a request to` worker-b` is canceled, as wrangler tail
says:
GET <some-url> - Canceled @ 4/14/2023, 5:03:23 PM
What can possibly go wrong about it? And why worker-b response is canceled whereas worker-a (both are set up literally the same) works just fine. By the way, worker responds with 200
, but due to the outcome: "canceled"
it is not taken into account ;/glynn
04/14/2023, 3:17 PMdelete_todo_dev.somedomain.workers.dev somedomain.workers.dev
This route is disabled by default and can only be enabled in the UI. We are trying to enable the
routes in Terraform so that we output the route's URL but as we didn't create the route,
we can't interact with it.
How is a Terraform project meant to create and manage routes programmatically?
If we use the Wrangler tool, then the route gets enabled on creation but using Terraform it doesn't.
We'd rather use Terraform than use Wrangler in a shell script, for obvious reasons.
Any best practice advise is very welcome.nora
04/14/2023, 8:44 PMjeffo
04/15/2023, 1:30 AMexport const onRequest: PagesFunction = async (context) => {
return new Response( 'foobar' )
}
while this code causes a typescript error:
import type {
PagesFunction,
} from '@cloudflare/workers-types/experimental'
export const onRequest: PagesFunction = async (context) => {
return new Response( 'foobar' )
}
the error i'm getting is:
Type '(context: EventContext<unknown, any, Record<string, unknown>>) => Promise<Response>' is not assignable to type 'PagesFunction'.
Type 'Promise<Response>' is not assignable to type 'Response | Promise<Response>'.
Type 'Promise<Response>' is not assignable to type 'Promise<import(".../node_modules/@cloudflare/workers-types/experimental/index").Response>'.
Type 'Response' is missing the following properties from type 'Response': webSocket, cf
i tried to ignore the error and delete the import type
bits, but it's nagging at me and i can't let it go. 🙂
any thoughts or advice? has anyone else run into the same problem?jeffo
04/15/2023, 9:39 PMJori
04/17/2023, 9:32 AMKartik
04/17/2023, 1:19 PMJoyte
04/18/2023, 3:46 AMcoolvibesreloaded
04/18/2023, 1:57 PMmercmoods
04/18/2023, 2:30 PMaye
04/18/2023, 5:39 PMSkye
04/18/2023, 6:17 PMnaosk8
04/19/2023, 6:26 AMQuick edit
section of the worker.
3. Confirm that the header has changed on the preview panel.
4. Save and deploy
5. Create a new Route settings for the worker (pattern: example.com/, zone: example.com)
6. access to https://example.com
→ The page is of course available like before, but the header is not changed like what was in the preview window (step 3-3). Also, the number of request didn't increase (it seems that my access is not routed to the worker).
Is there any step I missed? Or, anyone faced / solved the same problem?
Thank you.coolvibesreloaded
04/19/2023, 4:07 PMThatsTasty
04/19/2023, 7:20 PMrattlesnake
04/20/2023, 4:50 AMTino
04/20/2023, 12:59 PMTigersWay
04/21/2023, 12:26 AMmarcoow
04/21/2023, 10:45 AMasync fn request_sendgrid(api_key: &str, data: String) -> Result<u16, NetworkError> {
let mut opts = RequestInit::new();
opts.method("POST");
opts.mode(RequestMode::Cors);
opts.body(Some(&JsValue::from_str(&data)));
let request = FetchRequest::new_with_str_and_init(&"https://api.sendgrid.com/v3/mail/send", &opts)?;
request
.headers()
.set("Authorization", &format!("Bearer {}", api_key))?;
request.headers().set("Content-Type", "application/json")?;
let worker_global_scope = js_sys::global().dyn_into::<web_sys::ServiceWorkerGlobalScope>()?;
let resp_value = JsFuture::from(worker_global_scope.fetch_with_request(&request)).await?;
assert!(resp_value.is_instance_of::<FetchResponse>());
let response: FetchResponse = resp_value.dyn_into()?;
Ok(response.status())
}
The problem now is when running this, fetching the WASM fails with the above error at `build/worker/shim.mjs:181:20`:
function fetch(req, env, ctx) {
const ret = wasm.fetch(addHeapObject(req), addHeapObject(env), addHeapObject(ctx));
return takeObject(ret);
}
tabletoe
04/21/2023, 2:59 PMwallTime
here?ForwardMotion
04/21/2023, 5:11 PMmessage.headers.get('from')
as the object it puts it in the r2 bucket as expected with the content being the sender, but if i use message.headers.get('body')
it fails as if the object was empty.
question is what are the email headers and am i right to think that 'body' is not one of them. i can't seem to find the doc with all the possible headers. if body isn't the header for the email content is there one?woulduno
04/22/2023, 3:02 AMjwithing
04/23/2023, 3:14 AM樱花美子
04/23/2023, 1:46 PMhttps://www.pb2legacy.me:8443/assets/00b1287a89ec490d9bbb09011465a1c5.png▾
anteac
04/24/2023, 3:59 AMxorlop
04/24/2023, 1:12 PMenv
, env.dispatcher
, and the result of env.dispatcher.get(someString)
. Can anyone point me in the right direction? I was not able to find anything in @cloudflare/worker-types/index.d.ts
.... Also for env
itself, I kind of just type it like this:
type Env {
dispatcher: any;
}
The relevant documentation:
https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/
It does not contain any TS 😦
Quick search on GH returns this:
https://github.com/drivly/platform.workers.cf/blob/8fbdd76549b58414528611f75a04065fb1f49b12/src/env.ts#L9
Is that the recommended way to type this?firefall
04/24/2023, 5:51 PMranrub
04/24/2023, 9:03 PM