Skip to content

Commit

Permalink
Worker upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
a1ecbr0wn committed May 7, 2024
1 parent d04322d commit 6128bc1
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ jobs:
curl -s https://ident.me > idm.ip
if ! cmp -s prod.ip idm.ip; then
echo "::error title=Deploy Test Failure::IP addresses from id.a1ecbr0wn.com and ident.me do not match"
echo "Prod Response:"
cat prod.ip
echo "Control Response:"
cat idm.ip
exit 1
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1715103091]
Binary file not shown.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ console_error_panic_hook = { version = "0.1.7", optional = true }
[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"
lto = true
strip = true
codegen-units = 1
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"name": "id",
"private": true,
"version": "0.0.0",
"scripts": {
"deploy": "wrangler publish",
"deploy": "wrangler deploy",
"dev": "wrangler dev --local"
},
"devDependencies": {
"wrangler": "^2.16.0"
},
"dependencies": {
"wrangler": "^3.53.1",
"wrangler2": "^1.0.0"
}
}
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn log_request(req: &Request) {
req.cf()
.unwrap()
.region()
.unwrap_or_else(|| "unknown region".into())
.unwrap_or("unknown region".into())
);
}

Expand All @@ -27,6 +27,7 @@ pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> Result<Respo
let router = Router::new();

router
// .get("/", |_, _| Response::ok("Hello, World!"))
.get_async("/", |req, ctx| checked(req, ctx, |ip| Response::ok(ip)))
.get_async("/json", |req, ctx| {
checked(req, ctx, |ip| Response::from_json(&json!({ "ip": ip })))
Expand All @@ -37,8 +38,10 @@ pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> Result<Respo
Response::ok(version)
})
})
.get("/hello", |_, _| Response::ok("Hello, World!"))
.run(req, env)
.await
// Response::ok("Hello, World!")
}

// Check we have the ip header and check that the rate does not exceed the threshold
Expand All @@ -57,6 +60,8 @@ where
Response::error("Service unavailable :(", 503)
}
} else {
Response::error("Missing header", 424)
console_log!("Missing 'CF-Connecting-IP' header");
console_log!("{:?}", req.headers());
Response::error("Missing 'CF-Connecting-IP' header", 424)
}
}
12 changes: 6 additions & 6 deletions wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
name = "dev-id"
main = "build/worker/shim.mjs"
compatibility_date = "2022-01-20"
compatibility_date = "2023-12-01"
assets = "assets"
kv_namespaces = [
{ binding = "id", id = "444fcce1202948d59b0d2a326933c413", preview_id = "79d9e5086960445abc089e9d753e0fb5" }
]
vars = [
{ENVIRONMENT = "development"},
{WORKERS_RS_VERSION = "0.2.0"}
]
send_metrics = false

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

[env.test]
name = "test-id"
kv_namespaces = [
{ binding = "id", id = "fc0265ceaccd4f52883b236f1fdaf489" }
]
vars = [
{ENVIRONMENT = "test"},
{WORKERS_RS_VERSION = "0.2.0"}
]

[env.prod]
Expand All @@ -31,8 +32,7 @@ kv_namespaces = [
]
vars = [
{ENVIRONMENT = "production"},
{WORKERS_RS_VERSION = "0.2.0"}
]

[build]
command = "cargo install worker-build && worker-build --release"
[placement]
mode = "smart"

0 comments on commit 6128bc1

Please sign in to comment.