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

    kian

    04/27/2023, 9:31 PM
  • k

    kian

    04/27/2023, 9:31 PM
    There's an example there
  • s

    spacey

    04/27/2023, 10:02 PM
    When using queues with "Cloudflare Page Functions" do I need to use a
    _worker.js
    to put the consumer or can I do this some other way. Since the local dev enviroment does not allow me to have a _worker.js without an exported
    fetch
    which i don't need.
  • h

    HardAtWork

    04/27/2023, 10:07 PM
    To write a Queue Consumer, you need a Worker. Pages Functions does not support any non-fetch handlers, which includes Queues
  • s

    spacey

    04/27/2023, 10:08 PM
    I already have an extensive api using functions do i have to migrate that back to the worker just to use queues? since the
    functions
    folder is ignored with i introduce a _worker.js file
  • h

    HardAtWork

    04/27/2023, 10:12 PM
    Keep the Functions folder as is, delete the _worker.js file, and in a separate folder, build a Worker to handle your Queues
  • s

    spacey

    04/27/2023, 10:17 PM
    will try
  • s

    silentdevnull

    04/27/2023, 10:18 PM
    Thank you, I'm trying the example a different way now. I got this error
    Copy code
    Worker exceeded CPU time limit.
    when I tried it as it was.
  • l

    Larry

    04/27/2023, 10:22 PM
    To each his own, but I tried both and prefer js-yaml https://www.npmjs.com/package/js-yaml
  • k

    kian

    04/27/2023, 10:23 PM
    How many files are in the R2 bucket?
  • s

    silentdevnull

    04/27/2023, 10:26 PM
    I don't know the exact number but it less then 150. The whole bucket only 300mb
  • s

    silentdevnull

    04/27/2023, 11:20 PM
    I'm still getting that error on the CPU. l
  • s

    silentdevnull

    04/27/2023, 11:20 PM
    I will build a new bucket tomorrow and change to the new one and see if that fixes the issue.
  • k

    kian

    04/27/2023, 11:24 PM
    What's your exact code currently?
  • s

    silentdevnull

    04/27/2023, 11:36 PM
    Copy code
    export async function onRequest(context) {
    
        const options = {
            limit: 500,
            include: ['customMetadata'],
        };
    
        const listed = await context.env.NAME.list(options);
        console.log(listed);
        
        let truncated = listed.truncated;
        let cursor = truncated ? listed.cursor : undefined;
    
        while (listed.objects.length < options.limit) {
            console.log(listed.objects.name);
        }
        
        return new Response("Hello");
    }
    I couldn't find a fast way to count all the files I have in there so I will have to do that tomorrow.
  • k

    kian

    04/27/2023, 11:36 PM
    That's the example of what not to do
  • k

    kian

    04/27/2023, 11:36 PM
  • s

    silentdevnull

    04/27/2023, 11:49 PM
    so did I get them reversed? I get things flipped around thanks to me reading not the best
  • k

    kian

    04/28/2023, 12:02 AM
    Copy code
    js
    export async function onRequest(context) {
      const options = {
        limit: 500,
        include: ["customMetadata"],
      };
    
      const listed = await context.env.NAME.list(options);
    
      let truncated = listed.truncated;
      let cursor = truncated ? listed.cursor : undefined;
    
      while (truncated) {
        const next = await context.env.NAME.list({
          ...options,
          cursor: cursor,
        });
        listed.objects.push(...next.objects);
    
        truncated = next.truncated;
        cursor = next.cursor;
      }
    
      return Response.json(listed);
    }
  • k

    kian

    04/28/2023, 12:02 AM
    Use that
  • s

    silentdevnull

    04/28/2023, 1:30 AM
    Thank you that does work. Sorry for the miss understanding on the example and thank you for your help on it.
  • s

    spacey

    04/28/2023, 4:18 AM
    When using
    Hono
    does anyone know how to get
    cf.city, cf.timezone
    , etc.
    c.req.cf
    does not exist
  • c

    Chaika

    04/28/2023, 4:31 AM
    Looks like hono keeps the raw request object in c.req.raw, ex.
    Copy code
    js
    app.get('/', (c) => c.text(`Hello ${c.req.raw.cf?.city}`))
  • s

    spacey

    04/28/2023, 4:31 AM
    thanks i just went digging into the hono code and also saw this 🙂
  • s

    spacey

    04/28/2023, 5:17 AM
    What happens with a queue send call in dev
    env.QUEUE_NAME.send(data)
    ?
  • s

    spacey

    04/28/2023, 5:20 AM
    I'm curently runing the worker in a seperate window which is the consumer of queue is this the best local dev workflow for queues and cloudflare page functions?
  • s

    spacey

    04/28/2023, 5:23 AM
    How do I debug queues locally?
  • l

    Lloyd

    04/28/2023, 4:10 PM
    I'm finding it really really hard to understand how to use cloudflare page functions, I've been trying this for as few days now and honestly I feel like the docs are missing too much information.
    Copy code
    tsx
    export const onRequest: PagesFunction = async ({ request, next }) => {
        const response = await fetch(request);
    
        // Clone the response so that it's no longer immutable
        const newResponse = new Response(response.body, response);
    
        // Add a custom header with a value
        newResponse.headers.append(
          "x-workers-hello",
          "Hello from Cloudflare Workers"
        );
    
        await next();
    
        return newResponse;
    }
  • l

    Lloyd

    04/28/2023, 4:11 PM
    - Why is a function running in it's own page using a prohibited IP? - Why does the header get set dozens of times? - This happens with or without the await next() call
  • l

    Lloyd

    04/28/2023, 4:12 PM
    Why is this "expires" header set to unix epoch?
1...377378379...392Latest