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

    wonkrattle

    11/21/2021, 1:02 AM
    Does anybody know what this error is: “This readable stream is currently locked to a reader”
  • w

    wonkrattle

    11/21/2021, 1:14 AM
    @User so I ended up getting stuck, your initial code gave this error: “text: '"await" can only be used inside an "async" function” So I tried making it asynchronous only to get this “This readable stream is currently locked to a reader” which I had not seen before and which is basically not coming up in Google. https://github.com/datapolitical/chrisfnicholson.github.io/blob/cloudflare-functions/functions/index.js
  • w

    wonkrattle

    11/21/2021, 1:14 AM
    If anybody else wants to take a look I really appreciate it
  • g

    Greg Brimble | Cloudflare Pages

    11/21/2021, 1:20 AM
    Ah, sorry, just add the
    async
    keyword when defining the function
  • g

    Greg Brimble | Cloudflare Pages

    11/21/2021, 1:21 AM
    export const onRequestGet = async ({ request, next }) => {
  • w

    wonkrattle

    11/21/2021, 1:28 AM
    That makes sense given the error. I should’ve just done exactly what it said. Out of curiosity, how is that syntax different than the one at the top of the weather example
  • w

    wonkrattle

    11/21/2021, 1:28 AM
    export async function onRequest(context) { try { // Contents of context object const { request, // same as existing Worker API env, // same as existing Worker API params, // if filename includes [id] or [[path]] waitUntil, // same as ctx.waitUntil in existing Worker API next, // used for middleware or to fetch assets data, // arbitrary space for passing data between middlewares } = context;
  • w

    wonkrattle

    11/21/2021, 1:28 AM
    Like it seems to be doing something similar but not exactly the same
  • k

    kavinplays

    11/21/2021, 3:19 AM
    That is if you use the cache api on a function/worker
  • i

    ickerio

    11/21/2021, 4:27 AM
    Am I correct in saying that
    @sveltejs/adapter-cloudflare
    for cloudflare pages generates a
    _worker.js
    file, which means every page request is caught by the worker and counts towards my function requests which will eventually be billed?
  • k

    kavinplays

    11/21/2021, 4:34 AM
    afaik, yes
  • i

    itsmatteomanf

    11/21/2021, 9:13 AM
    Yes. Note that, as was said above, currently every method to add functions boils down to creating the
    _worker.js
    file, so it’s the same behaviour regardless.
  • i

    ickerio

    11/21/2021, 9:36 AM
    Ahh I see, thanks!
  • g

    Greg Brimble | Cloudflare Pages

    11/21/2021, 10:15 AM
    onRequestGet
    will only respond to GET requests whereas
    onRequest
    will respond to all requests. Rest of it is just down to personal preference though. Should be functionally identical.
  • w

    wonkrattle

    11/21/2021, 10:16 AM
    That’s what I was hoping you would say
  • w

    wonkrattle

    11/21/2021, 10:18 AM
    And the whole idea behind Wrangler is that instead of building the preview every 10 minutes to test a change I’ll be able to just test it locally, right
  • w

    wonkrattle

    11/21/2021, 10:21 AM
    And it looks like there’s a local mode as well, does the non-local mode count as a build?
  • k

    kavinplays

    11/21/2021, 10:27 AM
    i imagine so
  • g

    Greg Brimble | Cloudflare Pages

    11/21/2021, 10:29 AM
    There is no non-local
    wrangler pages dev
    at the moment.
  • g

    Greg Brimble | Cloudflare Pages

    11/21/2021, 10:30 AM
    We’re still thinking about it. What would you expect
    npx wrangler pages dev --remote
    to do?
  • k

    kavinplays

    11/21/2021, 10:31 AM
    just to be clear, it's local only atm, right?
  • g

    Greg Brimble | Cloudflare Pages

    11/21/2021, 10:31 AM
    Yes.
  • w

    wonkrattle

    11/21/2021, 10:50 AM
    https://blog.cloudflare.com/wrangler-v2-beta/ so this talks about having a local mode which is why I was confused because I thought the whole point was that it was local
  • w

    wonkrattle

    11/21/2021, 10:52 AM
    @User i’m sure there’s something I’m just not understanding because I’m new to all this
  • g

    Greg Brimble | Cloudflare Pages

    11/21/2021, 10:55 AM
    wrangler pages dev
    is entirely local. No builds are used when you’re testing with
    wrangler pages dev
    . Wrangler let’s you test Workers locally or remotely. We don’t have a remote equivalent for Pages yet. I was just wondering what you thought a remote version might look like. No biggie if you don’t have any thoughts on that. I was just curious 😊
  • w

    wonkrattle

    11/21/2021, 11:00 AM
    I guess a more controlled way to test how things behaved at the edge, especially if it didn’t require you to rebuild your entire site
  • w

    wonkrattle

    11/21/2021, 11:01 AM
    Like when dealing with Jekyll, there were always things that wouldn’t show up as a problem if you tested the site locally, but when you built it on the server other problems would come up
  • w

    wonkrattle

    11/21/2021, 11:03 AM
    And like, building a preview of my site takes 10 minutes, so I can imagine finding a way to have perhaps continuous local rebuilding that gets pushed up to the network would be really cool.
  • w

    wonkrattle

    11/21/2021, 11:05 AM
    And being able to put it up on your servers lets other people look at it as well while I’m working on it, without having to do a full preview rebuild.
  • k

    kavinplays

    11/21/2021, 11:06 AM
    That's what preview builds are for
1...111213...392Latest