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

    Unsmart | Tech debt

    01/11/2023, 6:50 PM
    I read it as per function in a project
  • w

    Walshy | Pages

    01/11/2023, 6:50 PM
    there's only 1 Function in a project :p
  • n

    Nico

    01/11/2023, 6:50 PM
    I see, they all run off the same worker?
  • w

    Walshy | Pages

    01/11/2023, 6:50 PM
    (the word "Function" is stupid yes and it can either mean the whole thing or a file)
  • u

    Unsmart | Tech debt

    01/11/2023, 6:50 PM
    thats technically true but you do create multiple files so yeah
  • w

    Walshy | Pages

    01/11/2023, 6:50 PM
    The
    functions
    dir will compile into 1 Worker yes
  • w

    Walshy | Pages

    01/11/2023, 6:51 PM
    you don't need to though 😉
  • n

    Nico

    01/11/2023, 6:51 PM
    Gotcha, I'll just create a separate worker in that case.
  • n

    Nico

    01/11/2023, 6:51 PM
    Is there a way to bind the same local KV for pages and a worker locally?
  • w

    Walshy | Pages

    01/11/2023, 6:52 PM
    Yeah if you use the same binding name it should use the same storage (assuming persistent)
  • n

    Nico

    01/11/2023, 6:54 PM
    Do you have to set it in a .toml file? I don't quite understand how --kv= can point to a local kv created with kv:namespaces without pointing the binding to the id?
  • n

    Nico

    01/11/2023, 6:56 PM
    like in the workers .toml file we have the binding here:
    Copy code
    kv_namespaces = [
      { binding = "METRICS_DATA", id = "xxx", preview_id = "yyy" },
    ]
    I want to point the pages dev kv binding to that preview_id namespace.
  • w

    Walshy | Pages

    01/11/2023, 6:56 PM
    The binding ID isn't used locally, it's the name which it saves under
  • w

    Walshy | Pages

    01/11/2023, 6:56 PM
    so
    --kv=METRICS_DATA
    is the same thing
  • n

    Nico

    01/11/2023, 6:59 PM
    Sure that makes sense, but then how do i point separate worker that im developing locally to that same binding?
  • n

    Nico

    01/11/2023, 7:00 PM
    i.e
    wrangler dev
    throws me an error:
    Copy code
    In development, you should use a separate kv namespace than the one you'd use in production. Please create a new kv namespace with "wrangler kv:namespace create <name> --preview" and add its id as preview_id to the kv_namespace "METRICS_DATA" in your wrangler.toml
  • s

    Skye

    01/11/2023, 7:03 PM
    You'll need to be using
    wrangler dev --local
  • n

    Nico

    01/11/2023, 7:03 PM
    Gave me the same error
  • s

    Skye

    01/11/2023, 7:03 PM
    It certainly shouldn't do that on local mode
  • n

    Nico

    01/11/2023, 7:04 PM
    do i need the preview_id kvnamespace setup?
  • s

    Skye

    01/11/2023, 7:08 PM
    it's irrelevant (or at least shouldn't be needed in the config) for local
  • n

    Nico

    01/11/2023, 7:09 PM
    Thats what I would think as well. I
  • n

    Nico

    01/11/2023, 7:19 PM
    Figured it out, had to add in --persist on both wrangler pages & wrangler dev --local. As well as add a dummy id of preview_id to bypass that error for some reason.
  • s

    Skye

    01/11/2023, 7:43 PM
    I'd suggest you make an issue about the dummy ID being needed for local mode at
  • i

    IanVS

    01/11/2023, 11:41 PM
    Is there anything I should know about using the aws sdk v3 in functions? Any gotchas that I should know about? I haven't found too much info out there about this combo so far.
  • z

    zszszsz

    01/12/2023, 12:29 AM
    Is it normal that I can match nothing with
    caches
    locally ?
  • z

    zszszsz

    01/12/2023, 12:32 AM
    Copy code
    ts
        const c = await caches.open('foo')
        await c.put('https://foo.foo/foo', new Response('foo'))
        console.log(await c.match('https://foo.foo/foo').then(v => v?.text()))
  • z

    zszszsz

    01/12/2023, 12:32 AM
    it returns
    undefined
  • z

    zszszsz

    01/12/2023, 12:45 AM
    solved. it must be
    new Response('foo', { headers: { Expires: new Date(Date.now() + 300_000).toUTCString() } })
    .
    Expires
    header is required.
  • y

    Yudai Nakata

    01/12/2023, 2:41 PM
    I've been struggling with this problem since the last reply, so I prepared a minimal reproduction repo at https://github.com/yudai-nkt/cloudflare-pages-etude. Pages Functions works as expected in production, i.e. clicking the counter button logs "Hello world!" in the DevTools' console. In local development, however, clicking the button logs the content of SPA instead of `/api/hello`'s response. What am I doing wrong? I might be missing something obvious but have no idea what that is.
1...330331332...392Latest