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

    Pause

    02/27/2023, 7:35 PM
    I'll do that
  • p

    Pause

    02/27/2023, 7:36 PM
    @kian it actually does exist and it generates a url, but it's not in the
    .d.ts
    file presumably because it can never work so it's pointless.
  • k

    kian

    02/27/2023, 7:36 PM
    I thought that's what
    createObjectURL
    was doing to be honest
  • k

    kian

    02/27/2023, 7:36 PM
    I had b64 data URLs in mind
  • p

    Pause

    02/27/2023, 7:37 PM
    I think it creates an address to binary data stored locally, but I could be wrong... I just don't know how else that tiny string would represent an image
  • d

    dave

    02/28/2023, 6:05 PM
    nope, it's basically a UUID
  • d

    dave

    02/28/2023, 6:06 PM
    Fetch the image, store it in R2, get the URL, and insert the R2 URL with HTMLRewriter.
  • p

    Pause

    02/28/2023, 6:23 PM
    @dave the images are relatively small; I just went with base64
  • h

    hanpolo

    02/28/2023, 8:08 PM
    Interesting observation on pages: I start my local development application using :
    Copy code
    npx wrangler pages dev -- npm start
    This then starts my application on localhost: where the port is determined by the npm start commands. Typically something like 33xx .. e.g. 3389 right now. But functions are accessible on localhost:8788 and it so happens that I have a call to one of these functions when the application is initializing. This call returns 404 not found, since my application is assuming the root is where its called from --i.e. localhost:33xx. If I call a function later on, the very same call succeeds, presumably because it is being proxied. Now if I force the early call to use localhost:8788, I get CORS policy error which prevents the function from running. The solution: after everything has initialized, I manually enter localhost:8788 in the address bar. Now everything works fine. Wouldn't it be better if the whole thing automatically started on localhost:8788. Though I wonder if then my changes will cause a restart on this address.
  • s

    Skye

    02/28/2023, 8:11 PM
    The whole thing should run on localhost:8788 - are you saying it doesn't?
  • h

    hanpolo

    02/28/2023, 8:11 PM
    Nope .. it starts on localhost:33xx presumably because of the "-- npm start" addition
  • s

    Skye

    02/28/2023, 8:12 PM
    That sounds like the port your second service is starting on - what port does the "Press b to open browser" give you?
  • h

    hanpolo

    02/28/2023, 8:12 PM
    let me see
  • h

    hanpolo

    02/28/2023, 8:13 PM
    http://127.0.0.1:8788/ .. I guess that is what I have to do to make it work right
  • h

    hanpolo

    02/28/2023, 8:13 PM
    the npm start from my command automatically starts a browser
  • h

    hanpolo

    02/28/2023, 8:14 PM
    FYI: I'm using stenciljs and start command is:
    Copy code
    stencil build --dev --watch --serve
  • s

    Skye

    02/28/2023, 8:17 PM
    Yeah, you shouldn't be using the port opened by the npm start command - use the one from wrangler
  • h

    hanpolo

    02/28/2023, 8:23 PM
    One other things is that pressing [b] for browser goes to 127.0.0.1:8788 and my api calls malfunction, since my cookies seem to not be set there, but localhost:8788 seems to work
  • a

    Asa Masterson

    03/03/2023, 1:19 PM
    was wondering of anyone could help me convert my cloudflare workers to a pages function due to not much documentation. I am trying to implement a simple viewcounter
    h
    l
    • 3
    • 10
  • t

    TKR👑

    03/05/2023, 3:09 AM
    Am I being dense, but should my
    /functions
    folder be in my root dir for the build? or my actual top level of a repo? Have tried both and neither seem to be working? Also are files with a
    -
    supported i.e
    /functions/early-access.js
    to
    domain.com/early-access
    ? Trying to get a simple hello world function working and just getting a 404 with nothing else 🥲
    • 1
    • 1
  • a

    Ariful

    03/05/2023, 8:39 AM
    Hi, anyone know how I can access request.body data in pages functions? I tried but I'm getting readablestream{} object like in the screenshot
  • h

    HardAtWork

    03/05/2023, 8:40 AM
    The type of Request/Response bodies are supposed to be ReadableStreams, if that is what you mean?
  • a

    Ariful

    03/05/2023, 8:41 AM
    I was trying to print the post data like const {email,name} = request.body, but I can't do that
  • h

    HardAtWork

    03/05/2023, 8:41 AM
    Is the body valid JSON?
  • a

    Ariful

    03/05/2023, 8:42 AM
    yeah
  • h

    HardAtWork

    03/05/2023, 8:42 AM
    Then do
    Copy code
    js
    const { email, name } = await req.json();
  • a

    Ariful

    03/05/2023, 8:43 AM
    okey let me try
  • a

    Ariful

    03/05/2023, 9:40 AM
    thanks it worked
  • s

    sdev

    03/05/2023, 12:56 PM
    Does Functions support text/event-stream request?
  • a

    Ariful

    03/05/2023, 12:59 PM
    does anyone know how to use D1 database on local environment with pages functions? I was able to setup a d1 database with functions, but it only work on cloudflare not on my local environment, seems I wasn't able to create a local database for d1,
1...354355356...392Latest