Skip to content

Commit

Permalink
Cloudflare workers example (#154)
Browse files Browse the repository at this point in the history
* Cloudflare workers examples

* Use /fetch component

* Add README
  • Loading branch information
jackkleeman authored Jun 24, 2024
1 parent a32765b commit 5293cde
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 1 deletion.
1 change: 1 addition & 0 deletions templates/cloudflare-worker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.wrangler
7 changes: 7 additions & 0 deletions templates/cloudflare-worker/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "all",
"tabWidth": 2,
"semi": true,
"arrowParens": "always",
"printWidth": 120
}
13 changes: 13 additions & 0 deletions templates/cloudflare-worker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Hello world - Cloudflare workers + Typescript example

Sample project configuration of a Restate service using the TypeScript SDK and
Cloudflare Workers.

Have a look at the [TypeScript Quickstart guide](https://docs.restate.dev/get_started/quickstart?sdk=ts) for more information about the SDK.

You can run locally with `npm run dev` and register to Restate with
`restate dep add http://localhost:9080 --use-http1.1`. `--use-http1.1` is needed
with the local Workers dev server, as it does not expose HTTP2.

You can deploy to cloudflare with `npm run deploy` and register to Restate with
`restate dep add https://restate-cloudflare-worker.<your-subdomain>.workers.dev`.
21 changes: 21 additions & 0 deletions templates/cloudflare-worker/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "restate-cloudflare-worker-template",
"type": "module",
"version": "0.0.1",
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev --port 9080",
"start": "wrangler dev --port 9080",
"format": "prettier --write \"src/*.+(js|ts|json)\""
},
"dependencies": {
"@restatedev/restate-sdk": "^1.0.1"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240605.0",
"prettier": "^3.3.2",
"typescript": "^5.4.5",
"wrangler": "^3.0.0"
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
17 changes: 17 additions & 0 deletions templates/cloudflare-worker/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Context, endpoint, service } from "@restatedev/restate-sdk/fetch";

// Template of a Restate service and handler
//
// Have a look at the TS QuickStart: https://docs.restate.dev/get_started/quickstart?sdk=ts
//

const greeter = service({
name: "greeter",
handlers: {
greet: async (ctx: Context, greeting: string) => {
return `${greeting}!`;
},
},
});

export default endpoint().bind(greeter).handler();
13 changes: 13 additions & 0 deletions templates/cloudflare-worker/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"noEmit": true,
"module": "nodenext",
"target": "esnext",
"lib": ["esnext"],
"strict": true,
"moduleResolution": "nodenext",
"types": ["@cloudflare/workers-types"],
"skipLibCheck": true
},
"exclude": ["node_modules", "dist", "test"]
}
4 changes: 4 additions & 0 deletions templates/cloudflare-worker/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name = "restate-cloudflare-worker"
main = "./src/index.ts"
compatibility_date = "2024-05-13"
compatibility_flags = [ "nodejs_compat" ]
2 changes: 1 addition & 1 deletion templates/typescript-lambda-cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"typescript": "^5.4.5"
},
"dependencies": {
"@restatedev/restate-sdk": "^1.0.0",
"@restatedev/restate-sdk": "^1.0.1",
"aws-cdk-lib": "^2.145.0",
"constructs": "^10.3.0",
"source-map-support": "^0.5.21"
Expand Down

0 comments on commit 5293cde

Please sign in to comment.