kwhitley / itty-durable

Cloudflare Durable Objects + Itty Router = shorter code
MIT License
251 stars 18 forks source link

How do you pass the request object and Params into the middleware/services? #5

Open repzip opened 3 years ago

repzip commented 3 years ago

Great module... I have spent a good bit of time trying to figure out how to pass params and request object into methods of the Durable Object?

Any help would be great.

Thanks.

savikko commented 3 years ago

I spent few moments with same thing and came up with this:

import {
   [...]
  withParams,
  withContent,
} from "itty-router-extras";

[...]

router.post("/test/:id", withParams, withContent,
  async({content,DurableObject,id}) => {
    console.log(`This is ${content} with id ${id}`);
    const object = DurableObjects.get(id);
    return object.toJSON();
});
kwhitley commented 3 years ago

Hold on, let me dust the cobwebs off! I know there's a way because this was obv a common use-case (have to be able to use other KV/durables from within a durable, for instance) :)

kwhitley commented 3 years ago

I had to shelve this temporarily (I'll be back, because I need it) for a death in the family :'(

repzip commented 3 years ago

Terribly sorry to hear that, my condolences. I will mess around with it today and try figure it out.

subhendukundu commented 2 years ago

Post methods dont work?

sinitsa commented 2 years ago

Post methods dont work?

Just in example, route with withDurable - is 'get' - just change it to 'all' ;)

router .all('*', withDurables())