File tree Expand file tree Collapse file tree 7 files changed +49
-56
lines changed
packages/create-cloudflare/templates
hello-world-durable-object-with-assets
hello-world-durable-object Expand file tree Collapse file tree 7 files changed +49
-56
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " create-cloudflare " : minor
3+ ---
4+
5+ Update create-cloudflare hello-world Durable Objects templates to use ` getByName() `
Original file line number Diff line number Diff line change @@ -52,17 +52,15 @@ export default {
5252 * @returns {Promise<Response> } The response to be sent back to the client
5353 */
5454 async fetch ( request , env , ctx ) {
55- // Create a `DurableObjectId` for an instance of the `MyDurableObject`
56- // class named "foo". Requests from all Workers to the instance named
57- // "foo" will go to a single globally unique Durable Object instance.
58- const id = env . MY_DURABLE_OBJECT . idFromName ( "foo" ) ;
59-
60- // Create a stub to open a communication channel with the Durable
61- // Object instance.
62- const stub = env . MY_DURABLE_OBJECT . get ( id ) ;
55+ // Create a stub to open a communication channel with the Durable Object
56+ // instance named "foo".
57+ //
58+ // Requests from all Workers to the Durable Object instance named "foo"
59+ // will go to a single remote Durable Object instance.
60+ const stub = env . MY_DURABLE_OBJECT . getByName ( "foo" ) ;
6361
6462 // Call the `sayHello()` RPC method on the stub to invoke the method on
65- // the remote Durable Object instance
63+ // the remote Durable Object instance.
6664 const greeting = await stub . sayHello ( "world" ) ;
6765
6866 return new Response ( greeting ) ;
Original file line number Diff line number Diff line change @@ -50,17 +50,15 @@ async def say_hello(self, name):
5050"""
5151class Default (WorkerEntrypoint ):
5252 async def fetch (self , request ):
53- # Create a `DurableObjectId` for an instance of the `MyDurableObject`
54- # class named "foo". Requests from all Workers to the instance named
55- # "foo" will go to a single globally unique Durable Object instance.
56- id = self .env .MY_DURABLE_OBJECT .idFromName ("foo" )
53+ # Create a stub to open a communication channel with the Durable Object
54+ # instance named "foo".
55+ #
56+ # Requests from all Workers to the Durable Object instance named "foo"
57+ # will go to a single remote Durable Object instance.
58+ stub = self .env .MY_DURABLE_OBJECT .getByName ("foo" )
5759
58- # Create a stub to open a communication channel with the Durable
59- # Object instance.
60- stub = self .env .MY_DURABLE_OBJECT .get (id )
61-
62- # Call the `say_hello()` RPC method on the stub to invoke the method on
63- # the remote Durable Object instance
60+ # Call the `say_hello()` RPC method on the stub to invoke the method on
61+ # the remote Durable Object instance.
6462 greeting = await stub .say_hello ("world" )
6563
6664 return Response (greeting )
Original file line number Diff line number Diff line change @@ -49,17 +49,15 @@ export default {
4949 * @returns The response to be sent back to the client
5050 */
5151 async fetch ( request , env , ctx ) : Promise < Response > {
52- // Create a `DurableObjectId` for an instance of the `MyDurableObject`
53- // class named "foo". Requests from all Workers to the instance named
54- // "foo" will go to a single globally unique Durable Object instance.
55- const id : DurableObjectId = env . MY_DURABLE_OBJECT . idFromName ( "foo" ) ;
56-
57- // Create a stub to open a communication channel with the Durable
58- // Object instance.
59- const stub = env . MY_DURABLE_OBJECT . get ( id ) ;
52+ // Create a stub to open a communication channel with the Durable Object
53+ // instance named "foo".
54+ //
55+ // Requests from all Workers to the Durable Object instance named "foo"
56+ // will go to a single remote Durable Object instance.
57+ const stub = env . MY_DURABLE_OBJECT . getByName ( "foo" ) ;
6058
6159 // Call the `sayHello()` RPC method on the stub to invoke the method on
62- // the remote Durable Object instance
60+ // the remote Durable Object instance.
6361 const greeting = await stub . sayHello ( "world" ) ;
6462
6563 return new Response ( greeting ) ;
Original file line number Diff line number Diff line change @@ -52,17 +52,15 @@ export default {
5252 * @returns {Promise<Response> } The response to be sent back to the client
5353 */
5454 async fetch ( request , env , ctx ) {
55- // Create a `DurableObjectId` for an instance of the `MyDurableObject`
56- // class named "foo". Requests from all Workers to the instance named
57- // "foo" will go to a single globally unique Durable Object instance.
58- const id = env . MY_DURABLE_OBJECT . idFromName ( "foo" ) ;
59-
60- // Create a stub to open a communication channel with the Durable
61- // Object instance.
62- const stub = env . MY_DURABLE_OBJECT . get ( id ) ;
55+ // Create a stub to open a communication channel with the Durable Object
56+ // instance named "foo".
57+ //
58+ // Requests from all Workers to the Durable Object instance named "foo"
59+ // will go to a single remote Durable Object instance.
60+ const stub = env . MY_DURABLE_OBJECT . getByName ( "foo" ) ;
6361
6462 // Call the `sayHello()` RPC method on the stub to invoke the method on
65- // the remote Durable Object instance
63+ // the remote Durable Object instance.
6664 const greeting = await stub . sayHello ( "world" ) ;
6765
6866 return new Response ( greeting ) ;
Original file line number Diff line number Diff line change @@ -50,17 +50,15 @@ class Default(WorkerEntrypoint):
5050 * @returns {Promise<Response>} The response to be sent back to the client
5151 """
5252 async def fetch (self , request ):
53- # Create a `DurableObjectId` for an instance of the `MyDurableObject`
54- # class named "foo". Requests from all Workers to the instance named
55- # "foo" will go to a single globally unique Durable Object instance.
56- id = self .env .MY_DURABLE_OBJECT .idFromName ("foo" )
53+ # Create a stub to open a communication channel with the Durable Object
54+ # instance named "foo".
55+ #
56+ # Requests from all Workers to the Durable Object instance named "foo"
57+ # will go to a single remote Durable Object instance.
58+ stub = self .env .MY_DURABLE_OBJECT .getByName ("foo" )
5759
58- # Create a stub to open a communication channel with the Durable
59- # Object instance.
60- stub = self .env .MY_DURABLE_OBJECT .get (id )
61-
62- # Call the `say_hello()` RPC method on the stub to invoke the method on
63- # the remote Durable Object instance
60+ # Call the `say_hello()` RPC method on the stub to invoke the method on
61+ # the remote Durable Object instance.
6462 greeting = await stub .say_hello ("world" )
6563
6664 return Response (greeting )
Original file line number Diff line number Diff line change @@ -48,17 +48,15 @@ export default {
4848 * @returns The response to be sent back to the client
4949 */
5050 async fetch ( request , env , ctx ) : Promise < Response > {
51- // Create a `DurableObjectId` for an instance of the `MyDurableObject`
52- // class named "foo". Requests from all Workers to the instance named
53- // "foo" will go to a single globally unique Durable Object instance.
54- const id : DurableObjectId = env . MY_DURABLE_OBJECT . idFromName ( "foo" ) ;
55-
56- // Create a stub to open a communication channel with the Durable
57- // Object instance.
58- const stub = env . MY_DURABLE_OBJECT . get ( id ) ;
51+ // Create a stub to open a communication channel with the Durable Object
52+ // instance named "foo".
53+ //
54+ // Requests from all Workers to the Durable Object instance named "foo"
55+ // will go to a single remote Durable Object instance.
56+ const stub = env . MY_DURABLE_OBJECT . getByName ( "foo" ) ;
5957
6058 // Call the `sayHello()` RPC method on the stub to invoke the method on
61- // the remote Durable Object instance
59+ // the remote Durable Object instance.
6260 const greeting = await stub . sayHello ( "world" ) ;
6361
6462 return new Response ( greeting ) ;
You can’t perform that action at this time.
0 commit comments