Skip to content

Commit

Permalink
initial rust worker template
Browse files Browse the repository at this point in the history
  • Loading branch information
j-white committed May 2, 2024
1 parent bfafef2 commit 9438e8a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
/node_modules
16 changes: 16 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "worker-rust"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
worker = "0.0.18"

[profile.release]
opt-level = "s" # optimize for size in release builds
lto = true
strip = true
codegen-units = 1
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "template-worker-rust",
"version": "0.0.0",
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev --env dev"
},
"devDependencies": {
"wrangler": "^3.1.2"
}
}
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use worker::*;

#[event(fetch)]
async fn main(req: Request, env: Env, ctx: Context) -> Result<Response> {
Response::ok("Hello, World!")
}
9 changes: 9 additions & 0 deletions wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name = "worker-rust"
main = "build/worker/shim.mjs"
compatibility_date = "2023-12-01"

[build]
command = "cargo install -q worker-build && worker-build --release"

[env.dev]
build = { command = "cargo install -q worker-build && worker-build --dev" }

0 comments on commit 9438e8a

Please sign in to comment.