Skip to content

Commit 02bd63c

Browse files
committed
fix code blocks
1 parent 488c3a2 commit 02bd63c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/content/docs/workflows/build/call-workflows-from-pages.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Your Worker can expose a specific method (or methods) that only other Workers or
4040
In the following example, we expose a specific `createInstance` method that accepts our `Payload` and returns the [`InstanceStatus`](/workflows/build/workers-api/#instancestatus) from the Workflows API:
4141

4242
<TypeScriptExample filename="index.ts">
43+
```ts
4344
import { WorkerEntrypoint } from "cloudflare:workers";
4445

4546
interface Env {
@@ -65,11 +66,13 @@ export default class WorkflowsService extends WorkerEntrypoint<Env> {
6566
});
6667
}
6768
}
69+
```
6870
</TypeScriptExample>
6971

7072
Your Pages Function would resemble the followijng:
7173

7274
<TypeScriptExample filename="functions/request.ts">
75+
```ts
7376
interface Env {
7477
WORKFLOW_SERVICE: Service;
7578
}
@@ -79,6 +82,7 @@ export const onRequest: PagesFunction<Env> = async (context) => {
7982
let payload = {"hello": "world"}
8083
return context.env.WORKFLOWS_SERVICE.createInstance(payload)
8184
};
85+
```
8286
</TypeScriptExample>
8387

8488
Visit the [bindings documentation for Pages Functions](/pages/functions/bindings/#service-bindings) to learn more about binding to resources from Pages Functions, including how to bind via the Cloudflare dashboard.
@@ -96,6 +100,7 @@ Service Bindings don't require you to expose a public endpoint from your Worker,
96100
An alternative to setting up a Service Binding is to call the Worker over HTTP by using the Workflows [Workers API](/workflows/build/workers-api/#workflow) to `create` a new Workflow instance for each incoming HTTP call to the Worker:
97101

98102
<TypeScriptExample filename="index.ts">
103+
```ts
99104
// This is in the same file as your Workflow definition
100105
export default {
101106
async fetch(req: Request, env: Env): Promise<Response> {
@@ -108,11 +113,13 @@ export default {
108113
});
109114
},
110115
};
116+
```
111117
</TypeScriptExample>
112118

113119
Your [Pages Function](/pages/functions/get-started/) can then make a regular `fetch` call to the Worker:
114120

115121
<TypeScriptExample filename="functions/request.ts">
122+
```ts
116123
export const onRequest: PagesFunction<Env> = async (context) => {
117124
// Other code
118125
let payload = {"hello": "world"}
@@ -122,6 +129,7 @@ export const onRequest: PagesFunction<Env> = async (context) => {
122129
}
123130
return Response.json(instanceStatus);
124131
};
132+
```
125133
</TypeScriptExample>
126134
127135
You can also choose to authenticate these requests by passing a shared secret in a header and validating that in your Worker.

0 commit comments

Comments
 (0)