Skip to content

Commit

Permalink
feat(worker): init
Browse files Browse the repository at this point in the history
  • Loading branch information
Gowee committed Nov 29, 2024
1 parent 8f414da commit adfec05
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions worker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target
node_modules
.wrangler
22 changes: 22 additions & 0 deletions worker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "zhconv-worker"
version = "0.1.0"
edition = "2021"
authors = [ "Hung-I Wang <[email protected]>" ]

[package.metadata.release]
release = false

# https://github.com/rustwasm/wasm-pack/issues/1247
[package.metadata.wasm-pack.profile.release]
wasm-opt = false

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

[dependencies]
worker = { version="0.4.2", features=['http', 'axum'] }
worker-macros = { version="0.4.2", features=['http'] }
axum = { version = "0.7", default-features = false }
tower-service = "0.3.2"
console_error_panic_hook = { version = "0.1.1" }
21 changes: 21 additions & 0 deletions worker/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use axum::{routing::get, Router};
use tower_service::Service;
use worker::*;

fn router() -> Router {
Router::new().route("/", get(root))
}

#[event(fetch)]
async fn fetch(
req: HttpRequest,
_env: Env,
_ctx: Context,
) -> Result<axum::http::Response<axum::body::Body>> {
console_error_panic_hook::set_once();
Ok(router().call(req).await?)
}

pub async fn root() -> &'static str {
"Hello Axum!"
}
6 changes: 6 additions & 0 deletions worker/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name = "worker"
main = "build/worker/shim.mjs"
compatibility_date = "2024-11-29"

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

0 comments on commit adfec05

Please sign in to comment.