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

    minimusubi

    03/07/2022, 9:44 AM
    since I forgot to mention in the original response, this seems to be the issue (other routes removed)
    Copy code
    json
    {
      "routes": {
        "GET /api/stop/search/near/:latitude]/[longitude": {
          "module": [
            "api/stop/search/near/[latitude]/[longitude].ts:onRequestGet"
          ]
        }
      },
      "baseURL": "/"
    }
  • c

    csmykay

    03/07/2022, 7:32 PM
    what is the best way to log what is happening in a function right now?
  • c

    csmykay

    03/07/2022, 8:31 PM
    There is no log feature like that of Workers. Do we just write our own log system to store it somewhere? Would love to store it in R2 but don't have access to that yet 😦
  • j

    James

    03/07/2022, 8:33 PM
    Yeah for now the best way is to pipe off the logs to some external system via
    waitUntil
    or similar. I believe there will be a better way to get Functions logs in the future, similar to normal Workers, once Functions hits GA.
  • j

    justinhook

    03/08/2022, 12:22 AM
    yes, renaming my firebase /functions directory has prevented my cloudflare workers requests from exceeding 105% of max every day!
  • c

    cojo

    03/08/2022, 3:37 AM
    asking this here as well as #773219443911819284 in case this is a better spot for it... I'm trying to figure out from various different repos / docs references exactly how I should best go about creating a new Durable Object for a new Pages Functions project / use case. Ideally, I'd like them to live in the same repo and have the least deployment separation / overhead possible (i.e. I'd prefer to deploy new Durable Object code alongside new Pages / Functions code, if possible). I get the loose sense that maybe I need to create the Durable Object in its own folder / deploy it completely independently, but it's not 100% clear to me if that's correct and even if so what the "best way" to manage that is to keep them in sync. Also not clear whether I should be using wrangler@beta or 1.19+ still, etc... anyone here who can advise what is possible and what is best practice ATM? Much appreciated in advance!
  • m

    MAXOUXAX

    03/08/2022, 5:27 PM
    Wondering about the same thing, would be cool to have an update! 🙂
  • h

    HardAtWork

    03/08/2022, 5:27 PM
    Easiest way is to deploy as a separate Worker.
  • m

    MAXOUXAX

    03/08/2022, 5:32 PM
    Woops, didn't see the discussion took place in #773219443911819284! Looking forward to the time when we'll be able to create Durable Objects from Pages Functions !
  • k

    King Mesal

    03/09/2022, 3:19 PM
    in functions on this page: https://developers.cloudflare.com/pages/platform/functions/ for utilizing path segments is says
    Copy code
    When naming your files:
    [name] is a placeholder for a single path segment.
    [[name]] matches any depth of route below this point.
    there are examples provided saying
    /api/todos/* => ./functions/api/todos/[id].ts
    In turn, the URL segment(s) that match the placeholder will be available under the context.params object using the filename placeholder as the key. Are there any code examples that show how to use that context.params object and how to properly reference the parts / pieces?
  • v

    VV

    03/09/2022, 10:20 PM
    Has anyone had the
    Only absolute URLs are supported
    error when using fetch and gatsby? I can't seem to find how to get the URL of a preview build to fix this error on production (using relative URLs gives this error too).
  • a

    Artis3n

    03/10/2022, 3:39 AM
    Copying from #789155108529111069 as it seems relevant for here: Question about setting an environment value based on the subdomain of a Pages preview deployment - I have a Nuxt site hitting CORS issues trying to hit the API endpoints I've set up with the beta Functions feature. Only occuring on the preview builds from PRs. I have the following axios configuration in my nuxt config:
    Copy code
    axios: {
        baseURL: 'http://localhost:3000/',
        browserBaseURL: 'http://localhost:3000/',
      },
    
      publicRuntimeConfig: {
        axios: {
          browserBaseURL: process.env.BROWSER_BASE_URL,
        },
      },
    
      privateRuntimeConfig: {
        axios: {
          baseURL: process.env.BASE_URL,
        },
      },
    I set the env vars to the production URL in the Pages settings. So the API functions work on the production deployment, but all testing from PRs is broken. I don't see env vars (https://developers.cloudflare.com/pages/platform/build-configuration/#environment-variables) available today that would help me resolve this. Is there a way?
  • a

    Artis3n

    03/10/2022, 3:42 AM
    Also: I have an
    onRequestPost()
    function set up and I'm logging the full context I receive. I don't see the POST body parameters anywhere. Shouldn't they be under
    context.request.body
    ? I POST an object containing the fields "page" and "token" and
    context.request.body
    is the object
    { locked: false }
    Any logs I can collect to help identify what is going on? POSTing like this from a Nuxt site:
    Copy code
    await $axios.$post('/api/checkToken', payload)
  • m

    minimusubi

    03/10/2022, 6:09 AM
    using the provided example, if we have a file at
    /functions/api/todos/[id].ts
    , if we were to visit the URL
    mydomain.dev/api/todos/133
    , then the
    context.params
    object will contain an
    id
    property that's set to
    "133"
    . Effectively,
    context.params.id = "133"
  • j

    jnordberg

    03/10/2022, 9:20 AM
    Any way to get logs from a _worker.js deployed to pages?
  • r

    richardcooke

    03/10/2022, 11:17 AM
    Seeing some behaviour that might be totally normal but struggling to explain it when using pages functions. We're using an
    _worker.js
    to server render a page, and it's stable and consistently fine. But if we smash the refresh button a few times it will
    1102 worker resource limits exceed
    . It recovers very quickly and then is consistently fine until the you aggressively refresh again. It also doesn't seem to affect other users in the same location, so if one user pushes the worker to
    1102
    , it seems to be isolated to that user. Is this expected/some kind of protection against users doing that? Or are we likely over/too close to the limits and actually pushing them over? It's difficult to tell whats going on with just the daily usage insights email.
  • w

    Walshy | Pages

    03/10/2022, 11:20 AM
    Sounds like you're hitting memory limits. A lot of requests from the same person in a short time will usually end up in the same isolate. Could you share your code?
  • i

    Isaac McFadyen | YYZ01

    03/10/2022, 1:19 PM
    Not yet, planned to be possible once Functions is out of beta but currently you'll need to send to an external log service like Honeycomb or Sentry.
  • a

    Artis3n

    03/10/2022, 1:29 PM
    Any thoughts on why I’m not seeing my post body parameters?
  • v

    vivekpatt_whyd

    03/10/2022, 2:39 PM
    Hi All, I am facing a weird issue. I have written functions in pages to add response header for a route which looks something like this (see configuration below) "/nl/fundraising/:slug": { "middleware": [ "nl/fundraising/[slug]/_middleware.ts:onRequest" ] } Now, I have also written Transform rules which will fallback all request to /nl/index.html so the Deep links will work. The weird issue is that due to the URL rewrite rules the request is not going through the function's middleware. And if i turn off the URL rewrite rules then Deep links will not work. Does any one have solution to this issue? Is this an issue with cloudflare or I am doing something wrong? Please note that, my project is based on angular v12 framework and it follows i18n build as per angular docs.
  • r

    richardcooke

    03/10/2022, 2:56 PM
    Tricky to share as the code as it's full react app, but memory limits would kinda makes sense if they hit the same isolate.
  • t

    TravisFrank

    03/10/2022, 5:12 PM
    Hey folks! I'm running into an issue deploying- I previously deployed with a
    functions
    dir with no issue, then removed the
    functions
    dir in a later build. I added the
    functions
    dir back in my most recent build, but now I'm running into
    Failed: an internal error occurred
    when deploying. Has anyone run into this before / quick fixes? Thanks so much!
  • t

    TravisFrank

    03/10/2022, 5:42 PM
    _worker.js file for above
    spoiler-worker
  • w

    Walshy | Pages

    03/10/2022, 5:43 PM
    Don't see any
    process
    or `global`s in there. What's the deployment ID?
  • v

    vivekpatt_whyd

    03/10/2022, 5:45 PM
    @User waiting for comments on this.
  • w

    Walshy | Pages

    03/10/2022, 5:46 PM
    You're saying if you enable a Transform Rule rewriting to
    /nl/index.html
    your Function isn't firing?
  • t

    TravisFrank

    03/10/2022, 5:50 PM
    Where can I find the deployment ID? I can't find it after doing some poking
  • w

    Walshy | Pages

    03/10/2022, 5:50 PM
    It's the UUID in the URL (we shouldn't really add this to the panel...)
  • t

    TravisFrank

    03/10/2022, 5:51 PM
    When it fails to deploy I don't have a URL to look at 😦
  • w

    Walshy | Pages

    03/10/2022, 5:51 PM
    The URL of your page when looking at the deployment
1...909192...392Latest