Skip to content

Commit

Permalink
Use workers-rs and other fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
awaitlink committed Mar 26, 2024
1 parent 0d3f04f commit 73e8a1f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ pkg/
wasm-pack.log
worker/generated/
.DS_Store
dist
build
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ qrcode = "0.14"
url = "2.5"
cfg-if = "1.0"
wasm-bindgen = "0.2"
worker = "0.0.13"

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
Expand Down
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use qrcode::{render::svg::Color, EcLevel, QrCode};
use std::{collections::HashMap, str::Split};
use url::Url;
use wasm_bindgen::prelude::*;
use worker::event;

cfg_if! {
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
Expand All @@ -16,6 +17,21 @@ cfg_if! {
}
}

#[event(fetch)]
pub async fn fetch(
req: worker::Request,
_env: worker::Env,
_ctx: worker::Context,
) -> worker::Result<worker::Response> {
let svg = handle_request(req.url()?.to_string())?;
let response = worker::Response::from_bytes(svg.as_bytes().to_vec())?;

let mut headers = worker::Headers::new();
headers.append("content-type", "image/svg+xml")?;

Ok(response.with_headers(headers))
}

struct Config {
pub min_size: Option<u32>,
pub max_size: Option<u32>,
Expand Down
10 changes: 0 additions & 10 deletions worker/metadata_wasm.json

This file was deleted.

13 changes: 0 additions & 13 deletions worker/worker.js

This file was deleted.

10 changes: 5 additions & 5 deletions wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "qr"
type = "rust"
zone_id = ""
private = false
account_id = ""
route = ""
workers_dev = true
compatibility_date = "2024-03-26"
main = "build/worker/shim.mjs"

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

0 comments on commit 73e8a1f

Please sign in to comment.