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

    Nopsled

    04/03/2023, 5:38 PM
    I am trying to do a request from Postman to the server running with: "npx wrangler pages dev --experimental-local --persist --compatibility-date=2023-04-03 -- npm run dev:vite" and running a api endpoint with help of tRPC. This is the output and the routing seems not to find the endpoint correctly. Trying to use the onRequest from pages functions..
  • s

    silentdevnull

    04/04/2023, 2:28 AM
    Can we use axios in side of functions or do they have to be in workers only? If we can use them how do we do the npm install for the fuctions directory
  • j

    James

    04/04/2023, 2:38 AM
    axios by default won’t work in Workers (and therefore Functions). Anything that works in workers will work in functions though, like
    fetch
  • s

    silentdevnull

    04/04/2023, 3:49 AM
    Oh I thought it would. Thank you for that information.
  • x

    xiang

    04/05/2023, 3:29 AM
    always build fail: 11:23:45.820 Success: Assets published! 11:23:47.717 Error: Failed to publish your Function. Got error: Error: Script startup exceeded CPU time limit. the limit time is too short😫
  • j

    James

    04/05/2023, 3:30 AM
    What kind of site are you building? Sounds like you have functions doing too much in the global scope and should move that to the incoming request scope
  • x

    xiang

    04/05/2023, 3:41 AM
    A light website build by next.js. only 5 functions ,every function code lines less than 200
  • x

    xiang

    04/05/2023, 3:43 AM
    build by next.js and next-on-page.
  • x

    xiang

    04/05/2023, 3:52 AM
    I guess the issue lies in this npm package: @nem035/gpt-3-encoder. It has many built-in encoding files, which causes the built worker to be too large in size.
  • j

    jaymakes11

    04/05/2023, 7:49 AM
    Is it possible to achieve this with Functions (this is an nginx reverse proxy setup)?
    Copy code
    nginx
    # load volument.js locally (with non-tracking related filename)
    location = /js/visits.js {
    
      # use volument-full.js for the banner version
      proxy_pass https://cdn.volument.com/v1/volument.js;
      proxy_set_header Host cdn.volument.com;
    
      # Performance improvement: cache the script for two hours
      proxy_cache jscache;
      proxy_cache_valid 200 2h;
      proxy_cache_use_stale updating error timeout invalid_header http_500;
    }
    
    
    # forward tracking events to volument edge servers
    location ~/visits/([123])(/.*)? {
      # google
      resolver 8.8.8.8 8.8.4.4;
      proxy_pass https://$1.t1.volument.com$2$is_args$args;
    }
    (trying to achieve, in a site hosted by Pages, this: https://volument.com/docs/ad-blockers)
  • g

    GeorgeTailor

    04/05/2023, 3:58 PM
    so, I can even do some crazy stuff like drawing images with OffscreenCanvas and stream it to the browser like a movie?
  • j

    James

    04/05/2023, 3:58 PM
    OffscreenCanvas
    isn't supported in Workers, so no, not really
  • j

    James

    04/05/2023, 3:59 PM
    There's a discussion at https://github.com/cloudflare/workerd/discussions/212 if you want to read more info
  • g

    GeorgeTailor

    04/05/2023, 4:03 PM
    cool, thanks. But still, a Function invocation is limited by time, 10ms on free and 50ms on paid plan, so not really feasible to do anything heavy or long-running
  • k

    kian

    04/05/2023, 4:07 PM
    It's CPU time rather than wall time so you can do a fair amount before it becomes an issue
  • j

    James

    04/05/2023, 4:40 PM
    Yep, CPU time only really becomes a problem if you're doing complex crypto or image generation via wasm or something. And then you can enable Unbound and get way more CPU time if you need it 🙂
  • s

    silentdevnull

    04/06/2023, 12:31 AM
    Does function not restore the packages.json? Is that something possible?
  • w

    William.

    04/06/2023, 12:45 AM
    If anyone has managed to make middleware works in a CSR angular project please send me a DM !
  • I am currently writing an Algolia
    m

    Matt Grah.am

    04/06/2023, 3:55 AM
    Below is the code for each: index.ts - https://gist.github.com/mattgrah-am/4ced19d9f8124cb7d8789c303b5c7049 webhook.ts - https://gist.github.com/mattgrah-am/0cbe9f5b9dc2a2bb08ef59f5030ef78c
    • 1
    • 1
  • a

    Antol

    04/06/2023, 3:30 PM
    Is there some secret to getting CF to recognize uploaded functions? My upload looks like this and the site works but it doesn't seem to recognize my submit.js function.
  • a

    Antol

    04/06/2023, 3:30 PM
    (Using Pages/functions)
  • h

    HardAtWork

    04/06/2023, 3:30 PM
    You can’t use Direct Upload if you want your Functions to work
  • a

    Antol

    04/06/2023, 3:30 PM
    Good to know
  • s

    Skye

    04/06/2023, 3:31 PM
    *direct upload in the browser
  • s

    Skye

    04/06/2023, 3:31 PM
    Wrangler will still work fine
  • a

    Antol

    04/06/2023, 3:33 PM
    Oh I see that now
  • a

    Antol

    04/06/2023, 3:47 PM
    Thank you @HardAtWork @Skye !
  • s

    silentdevnull

    04/06/2023, 11:23 PM
    Thank you for sharing that information. I was trying to do that just an hour ago.
  • s

    sdev

    04/07/2023, 7:34 AM
    What should we do to not face this issue in Pages Functions or other CF services? https://twitter.com/rauchg/status/1644099739959590912?s=46&t=g2WFwwkk3Rw_NTQpq7k45w
  • u

    Unsmart | Tech debt

    04/07/2023, 7:57 AM
    Pretty sure there's already a recursion limit in place and you don't pay anything for builds which was the broken part there
1...367368369...392Latest