https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-discussions
  • d

    Deleted User

    02/18/2023, 5:15 PM
    yah but while editing the html and having to escape every ` with \ is so annoying once pasted in js
  • h

    HardAtWork

    02/18/2023, 5:15 PM
    Copy code
    js
    import html from "./index.html";
    and your `wrangler.toml`:
    Copy code
    toml
    rules = [
      { type = "Text", globs = ["**/*.html"] }
    ]
  • d

    Deleted User

    02/18/2023, 5:15 PM
    lol
  • d

    Deleted User

    02/18/2023, 5:15 PM
    omg thank you
  • c

    Crazy Rabbit

    02/18/2023, 7:21 PM
    .body from fetch is readableStream, so you can't read it twice right?
  • c

    Crazy Rabbit

    02/18/2023, 7:21 PM
    but does it work if I assign it to a variable first like:
    Copy code
    js
    let value = result.body;
    and then use value 2 times?
  • k

    kian

    02/18/2023, 7:22 PM
    nope
  • k

    kian

    02/18/2023, 7:22 PM
    use
    tee()
    and it'll create two readable streams
  • k

    kian

    02/18/2023, 7:23 PM
    Copy code
    js
    const [ foo, bar ] = response.body.tee();
  • c

    Crazy Rabbit

    02/18/2023, 7:24 PM
    so I can then read foo once and bar once?
  • k

    kian

    02/18/2023, 7:24 PM
    they're both readablestreams that should be read in parallel
  • k

    kian

    02/18/2023, 7:24 PM
    i.e put one in cache/kv/r2 and return the other to the user
  • c

    Crazy Rabbit

    02/18/2023, 7:26 PM
    thanks
  • k

    kian

    02/18/2023, 7:28 PM
    Copy code
    js
    const response = await fetch(url);
    
    const [ resp_body, r2_body ] = response.body.tee();
    
    ctx.waitUntil(
      env.R2.put('foo', r2_body, { httpMetadata: response.headers });
    );
    
    return new Response(resp_body, response);
  • k

    kian

    02/18/2023, 7:28 PM
    that's how I use it in a Worker
  • k

    kian

    02/18/2023, 7:28 PM
    although I wrote all of that in Discord so the syntax could be Borked™️
  • s

    Skye

    02/18/2023, 7:28 PM
    looks right to me
  • d

    Dani Foldi

    02/18/2023, 7:28 PM
    LG™️
  • k

    kian

    02/18/2023, 7:28 PM
    like I forgot the filename in .put
  • s

    Skye

    02/18/2023, 7:29 PM
    I don't use the r2 bindings anyway, can't blame me
  • k

    kian

    02/18/2023, 7:30 PM
    🪣
  • c

    Crazy Rabbit

    02/18/2023, 7:30 PM
    2023-02-18-20-29-28
  • c

    Crazy Rabbit

    02/18/2023, 7:30 PM
    what about this?
  • c

    Crazy Rabbit

    02/18/2023, 7:30 PM
    look at TTL
  • c

    Crazy Rabbit

    02/18/2023, 7:30 PM
    on every request value is fetched from cache API
  • c

    Crazy Rabbit

    02/18/2023, 7:31 PM
    and sometimes different result is returned
  • k

    kian

    02/18/2023, 7:31 PM
    what colo on /cdn-cgi/trace?
  • c

    Crazy Rabbit

    02/18/2023, 7:31 PM
    Copy code
    fl=608f51
    h=dns.rabbitdns.org
    ts=1676748698.544
    visit_scheme=https
    uag=got (https://github.com/sindresorhus/got)
    colo=FRA
    sliver=none
    http=http/1.1
    loc=SI
    tls=TLSv1.3
    sni=plaintext
    warp=off
    gateway=off
    rbi=off
    kex=X25519
  • c

    Crazy Rabbit

    02/18/2023, 7:32 PM
    FRA
  • k

    kian

    02/18/2023, 7:32 PM
    FRA is like ~8 colos and each have their own cache
1...228322842285...2509Latest