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

    Cоlе

    01/08/2022, 5:12 AM
    I know that you can use relative paths for it, which can be useful when deploying to multiple domains
  • c

    Cоlе

    01/08/2022, 5:12 AM
    I don't think you can relative fetch on functions but I could be wrong
  • h

    HardAtWork

    01/08/2022, 5:14 AM
    Can you share the code snippet?
  • c

    Cоlе

    01/08/2022, 5:15 AM
    I was just looking at this comment from greg from a few days ago https://github.com/cloudflare/wrangler2/issues/165#issuecomment-1004915159
  • s

    steranevdy

    01/08/2022, 5:16 AM
    i think in preview/production env you will need to pass the actual request object
  • s

    steranevdy

    01/08/2022, 5:16 AM
    it seems to work differently on local vs preview/prod
  • c

    Cоlе

    01/08/2022, 5:17 AM
    lots of things do 😮‍💨
  • c

    Cоlе

    01/08/2022, 5:56 AM
    sorry for late, I didn't see your reply
  • c

    Cоlе

    01/08/2022, 5:56 AM
    I have the big tired
  • c

    Cоlе

    01/08/2022, 5:56 AM
    If I so much as
    let cache = await caches.open('<name>');
    it breaks
  • c

    Cоlе

    01/08/2022, 5:57 AM
    on
    wrangler@alpha
  • c

    Cоlе

    01/08/2022, 5:57 AM
    and beta
  • c

    Cоlе

    01/08/2022, 5:59 AM
    Copy code
    Compiling worker to "/tmp/functionsWorker.js"...
    Compiled Worker successfully.
    [pages:err] SyntaxError: Unexpected reserved word
        at new Module (node:internal/vm/module:123:21)
        at new SourceTextModule (node:internal/vm/module:297:5)
    more stack trace, but privacy
  • c

    Cоlе

    01/08/2022, 6:01 AM
    doing a big big deploy on sunday, so just wanna make sure it's not my fault lol
  • h

    HardAtWork

    01/08/2022, 6:55 AM
    Yeah, that looks right. Maybe try the #799437470004412476 channel and see if someone knows what might be going wrong?
  • c

    Cоlе

    01/08/2022, 6:58 AM
    Good thinking, I'll try there
  • c

    Cоlе

    01/08/2022, 9:00 AM
    Ok for reference, the problem was that I was declaring cache outside of a handler
  • c

    Cоlе

    01/08/2022, 9:01 AM
    Which seems to work for mongo realm? But not for cache
  • c

    Cоlе

    01/08/2022, 9:01 AM
    I'm probably wrong, don't fact check that one
  • c

    Cоlе

    01/08/2022, 9:02 AM

    https://c.tenor.com/ZGjJDiolyuIAAAAM/kid-puzzle.gif▾

  • c

    Cоlе

    01/08/2022, 9:06 AM
    I was wrong. Note to future Cole: conditional declarations are okay
  • r

    rkusa

    01/08/2022, 10:19 AM
    Ah right, I have
    trailingSlash
    enabled, which is why in my next app dynamic routes are exported to
    /index.html
    . I gave it a test (with
    trailingSlash
    not enabled) and the following function works for me (it is written a bit different to yours, but I'd have thought that they both are basically the same):
    Copy code
    js
    export function onRequestGet({ env, request }) {
      return env.ASSETS.fetch(
        new Request(new URL("/profiles/[profile]", request.url).toString(), request)
      );
    }
    (no rewrite: ; with rewrite: )
  • j

    Jaren

    01/08/2022, 10:22 AM
    will try it out
  • j

    Jaren

    01/08/2022, 10:29 AM
    i'll be damned, it works!
  • j

    Jaren

    01/08/2022, 10:29 AM
    i've been stuck on this issue for a while
  • r

    rkusa

    01/08/2022, 11:40 AM
    Cool, I am glad it works, though I still have no idea why it works compared to your snippet 🤷‍♂️
  • d

    Dude

    01/09/2022, 6:51 AM
    Does running
    npx wrangler pages dev "public"
    also run ./functions locally?
  • d

    Dude

    01/09/2022, 6:55 AM
    When visiting http://localhost:8788/api/collections, the response is the html from the "public" directory, not the function response. 😕
  • d

    dfcowell

    01/09/2022, 7:20 AM
    Why are you specifying the
    public
    directory in your command? Are you using a framework, or just static assets + functions?
  • g

    Greg Brimble | Cloudflare Pages

    01/09/2022, 11:08 AM
    Should do! Does your
    functions
    folder exist in the same directory that you’re running wrangler?
1...555657...392Latest