https://discord.cloudflare.com logo
Join Discord
Powered by
# functions
  • g

    Greg Brimble | Cloudflare Pages

    04/20/2022, 4:14 PM
    We're going to add compatibility date ASAP
  • i

    Isaac McFadyen | YYZ01

    04/20/2022, 4:14 PM
    Yeah, I just mean on the build machine itself.
  • g

    Greg Brimble | Cloudflare Pages

    04/20/2022, 4:14 PM
    (I want it too!)
  • i

    Isaac McFadyen | YYZ01

    04/20/2022, 4:14 PM
    It looks like Functions uses Wrangler when deploying (there's a log there that shows that, anyway).
  • g

    Greg Brimble | Cloudflare Pages

    04/20/2022, 4:15 PM
    Ah, yeah, we use wrangler to compile your folder of Functions into a Worker, but we manage that
  • g

    Greg Brimble | Cloudflare Pages

    04/20/2022, 4:15 PM
    It does the same thing that happens when you use
    wrangler dev
    locally šŸ™‚
  • c

    Cоlе

    04/21/2022, 1:37 AM
    I'm running into an interesting problem w/ HTMLRewriter and middleware:
  • c

    Cоlе

    04/21/2022, 1:39 AM
    I have an
    index.ts
    and a
    _middleware.ts
    , and they both run HTMLRewriter in different ways. In wrangler, they both work fine, but when deployed to pages, the middleware one doesn't seem to work
  • c

    Cоlе

    04/21/2022, 1:39 AM
    it's definitely running, I can throw an error and it'll give 10XX, but otherwise the changes from
    _middleware.ts
    aren't getting reflected back in
    index.ts
  • c

    Cоlе

    04/21/2022, 1:40 AM
    have there been any issues lately that might be related?
  • c

    Cоlе

    04/21/2022, 1:58 AM
    https://github.com/Mexican-Man/pages-csp-generator you can wrangler this w/ a
    functions/index.ts
    or `functions/_middleware.ts`:
    Copy code
    ts
    import { InjectCSPTags } from "../csp";
    
    export const onRequest = [InjectCSPTags];
    and an html page
  • c

    Cоlе

    04/21/2022, 1:59 AM
    I was only trying
    _middleware.ts
    deployed, but
    _middleware.ts
    and
    index.ts
    (w/ index.html obv) work identically locally
  • e

    Erwin

    04/21/2022, 2:13 AM
    Hmmm.. this is certainly an interesting edge case. But in theory there should be nothing preventing you from chaining two HTMLRewriters together..
  • e

    Erwin

    04/21/2022, 2:14 AM
    I unfortunately don't have a lot of time over the next few days, but @Greg Brimble | Cloudflare Pages might be interested in including this functionality into a Pages Plugin.. (which is to say that I would be very interested in having a CSP generator as a Pages Plugin šŸ˜„ ).. so he might have some time to take a look?
  • n

    nanzepanze

    04/21/2022, 12:10 PM
    What's the support like for functions written in Go?
  • k

    kian

    04/21/2022, 12:12 PM
    As in Go code that's compiled to JavaScript/WebAssembly?
  • n

    nanzepanze

    04/21/2022, 12:12 PM
    Ok so you can't write Go code and deploy it as a Cloudflare function, it has to be compiled to JS or WASM?
  • k

    kian

    04/21/2022, 12:14 PM
    I'm not sure if WASM is supported (it is in Workers) yet in Functions, but overall yes - JavaScript is required.
  • g

    Greg Brimble | Cloudflare Pages

    04/21/2022, 12:14 PM
    No WASM in Functions yet ā˜¹ļø
  • g

    Greg Brimble | Cloudflare Pages

    04/21/2022, 12:15 PM
    I’ll try take a look at this today
  • c

    Cоlе

    04/22/2022, 7:32 AM
    ah I think I figured it out
  • c

    Cоlе

    04/22/2022, 7:34 AM
    half of it was me doing a bad job at handling
    next()
    , but HTMLRewriter just doesn't seem too happy when chaining requests sometimes
  • c

    Cоlе

    04/22/2022, 7:35 AM
    I resolved it by
    await
    -ing the first instance of HTMLRewriter, and that seemed to fix the issue
  • c

    Cоlе

    04/22/2022, 7:35 AM
    I don't have any concrete examples, I couldn't get anything to break/work consistently until now, so you can forget about it for now lol
  • o

    orstavik77

    04/22/2022, 8:21 AM
    I am wrestling with wrangler:) Does anyone know how I can connect to a KV data base when I run wrangler pages dev? On dash.cloudflare.com, the KV is called "TEST" with a "hello":"world" entry. Then in pages functions I have bound "TEST_DB" to "TEST". So that I in pages functions worker in production can call
    env.TEST_DB.get("hello")
    to get
    "world"
    and that works fine. But. How do I get to run and test this locally with
    wrangler pages dev
    ? I have tried
    npx wrangler pages dev . --kv TEST --binding TEST_DB=TEST
    ps: I am running wrangler2 beta.
  • s

    Skye

    04/22/2022, 8:22 AM
    binding is for environmental variables, you should just use
    --kv TEST_DB
  • o

    orstavik77

    04/22/2022, 8:22 AM
    nice, i try)
  • s

    Skye

    04/22/2022, 8:22 AM
    the wrangler pages KV is just a local copy of KV, and will not care about your bindings for production
  • o

    orstavik77

    04/22/2022, 8:25 AM
    maybe I am missing some pre-steps here. I get
    null
    instead for
    "world"
    .
  • o

    orstavik77

    04/22/2022, 8:25 AM
    I ran
    npx wrangler pages dev . --kv TEST_DB
1...125126127...392Latest