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

    Erwin

    02/13/2022, 3:55 AM
    Yeah.. it became a convention to redirect POST to GET and then the latest spec formalised that. 307 redirects are explicitly defined as to keep the same method.
  • e

    Erwin

    02/13/2022, 3:57 AM
    But tbh, I wouldn’t want my http to https redirection to preserve my POSTs. Make it fail so people can actually see that they are posting something over an insecure connection instead of working silently.
  • c

    Cоlе

    02/13/2022, 4:25 AM
    is that a standardized thing, or a cloudflare thing?
  • e

    Erwin

    02/13/2022, 4:38 AM
    The conversion of POST to GET or the redirecting from
    http
    to
    https
    ? The former is browser behaviour and the later is probably a setting somewhere? But in any way exactly what you want.
  • c

    Cоlе

    02/13/2022, 4:41 AM
    oh wow, I had no idea
  • c

    Cоlе

    02/13/2022, 4:41 AM
    I was just sitting here for a week wondering what I broke lol
  • c

    Cоlе

    02/13/2022, 4:42 AM

    https://tenor.com/RCPz.gif▾

  • e

    Erwin

    02/13/2022, 4:44 AM
    Copy code
    Note: In HTTP/1.0, the status codes 301 (Moved Permanently) and
          302 (Found) were defined for the first type of redirect
          ([RFC1945], Section 9.3).  Early user agents split on whether the
          method applied to the redirect target would be the same as the
          original request or would be rewritten as GET.  Although HTTP
          originally defined the former semantics for 301 and 302 (to match
          its original implementation at CERN), and defined 303 (See Other)
          to match the latter semantics, prevailing practice gradually
          converged on the latter semantics for 301 and 302 as well.  The
          first revision of HTTP/1.1 added 307 (Temporary Redirect) to
          indicate the former semantics without being impacted by divergent
          practice.  Over 10 years later, most user agents still do method
          rewriting for 301 and 302; therefore, this specification makes
          that behavior conformant when the original request is POST.
    https://datatracker.ietf.org/doc/html/rfc7231#section-6.4
  • e

    Erwin

    02/13/2022, 4:53 AM
    Another way to fix this is to use HTST header (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security). It will tell the browser to consider every HTTP request a HTTPS request.
  • s

    sandles

    02/13/2022, 2:55 PM
    Hey all, I am building a pages frontend using an "unsupported framework" (flutter), and I want to add some Functions as the backend. I am not sure how to do this, though. I was able to just add a
    /functions
    directory and get a hello world function to run, but how can I import packages if I don't have a
    package.json
    or anything in this flutter project? Do I just create one and have the JS stuff live next to the flutter stuff, unaware of each other?
  • s

    sandles

    02/13/2022, 3:21 PM
    > Do I just create one and have the JS stuff live next to the flutter stuff, unaware of each other? Update: I tried to do this, and Pages fails to build with an error
    ✘ [ERROR] Could not resolve "@tsndr/cloudflare-worker-jwt"
    How, exactly am I supposed to use NPM packages in functions?
  • w

    William | Chaos Management

    02/13/2022, 7:56 PM
    For functions, they would have to output to a functions folder inside of the folder with the built files, right?
  • w

    William | Chaos Management

    02/13/2022, 8:08 PM
    So if my output folder is /dist, the functions folder would be /dist/functions?
  • l

    Larry

    02/13/2022, 8:12 PM
    Thanks for trying, but I'm still missing some context so that doesn't really help me.
  • s

    stewfish

    02/13/2022, 10:57 PM
    @User Did you ever figure this one out. I have been seeing this error also but I am using SvelteKit as my framework. Like you if I click again it the expected page will show up but it is certainly not intuitive to see that error message while busy trying to develop and test things live on a local machine.
  • s

    stewfish

    02/13/2022, 11:02 PM
    Hello all, First of all thanks to the entire CF team for Workers and now Pages! With all that is being released and being worked on I am having a hard time finding the boundaries. With many of the frontend frameworks there is the concept of an "endpoint" which functionally does or seemingly can do the same things a Worker can. Maybe I am missing the real understanding behind it but when should one use an endpoint vs a Worker and vice-versa? What is really making things more confusing is I am currently having a hard time developing using svelte-kit + workers (vis functions) with
    adapter-cloudflare
  • i

    Isaac McFadyen | YYZ01

    02/13/2022, 11:02 PM
    So couple of things.
  • i

    Isaac McFadyen | YYZ01

    02/13/2022, 11:03 PM
    adapter-cloudflare
    basically packages up your SvelteKit project and puts it into a Worker (a Pages Function, which is similar to a worker).
  • i

    Isaac McFadyen | YYZ01

    02/13/2022, 11:03 PM
    So when you use
    adapter-cloudflare
    everything is dynamic. An endpoint is actually served by the main Worker automatically, there's no differentiation.
  • i

    Isaac McFadyen | YYZ01

    02/13/2022, 11:05 PM
    Every page rendered by SvelteKit using
    adapter-cloudflare
    will be rendered on the main worker. That includes endpoints. With SvelteKit using the
    adapter-cloudflare
    your only option is endpoints, you can't add an extra Function. But endpoints are all you need.
  • s

    stewfish

    02/13/2022, 11:06 PM
    Thank you so much! That should help stop me from straying into no man's land with the functions directory. Curious if I used
    adapter-static
    is that when the function comes back into play?
  • i

    Isaac McFadyen | YYZ01

    02/13/2022, 11:07 PM
    Yes, exactly. Using
    adapter-static
    will cause all of your pages to be prerendered, then you can manually add Functions for anything dynamic. But I would recommend against it, because that means any ``s in your
    .svelte
    files will be prerendered.
  • i

    Isaac McFadyen | YYZ01

    02/13/2022, 11:08 PM
    I'm using SvelteKit with
    adapter-cloudflare
    right now on my production site and it's wonderful.
  • b

    bryan.

    02/15/2022, 6:39 PM
    sorry for the late response but if you still need help please feel free to DM me!
  • i

    Ishan

    02/17/2022, 1:52 PM
    what is the cpu time limit in functions ? i heard somewhere that in beta its 50ms
  • i

    Isaac McFadyen | YYZ01

    02/17/2022, 1:53 PM
    I think it is, I'm consistently near 50ms for my functions but if anyone else would like to confirm?
  • e

    Erwin

    02/17/2022, 1:57 PM
    Yeah, they are running Bundled workers behind the scenes for now. Might change or be configurable. No decision made on that AFAIK
  • i

    Isaac McFadyen | YYZ01

    02/17/2022, 1:57 PM
    I'm all in support of that, even if I have to pay for the bundled after beta, since my site takes like 40ms to render 😄
  • e

    Erwin

    02/17/2022, 2:01 PM
    You would prefer those to be on Unbound then.. if you don’t have many long running fetch calls to make.
  • i

    Isaac McFadyen | YYZ01

    02/17/2022, 2:01 PM
    Why? I thought bundled was up to 50ms?
1...767778...392Latest