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

    Hazard

    04/09/2022, 9:10 PM
    if i send something properly, this is how it looks like

    https://i.imgur.com/RvBF5NA.png▾

  • h

    Hazard

    04/09/2022, 9:11 PM
    but postman could be doing some stuff that doesn't show me if it fails CORS
  • h

    Hazard

    04/09/2022, 9:12 PM
    The thing is, i get a 401 thrown from the browser as it should, but above it gives me that CORS error
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 9:12 PM
    Are you replying with JSON?
  • h

    Hazard

    04/09/2022, 9:12 PM
    ye, stringified
  • i

    Isaac McFadyen | YYZ01

    04/09/2022, 9:13 PM
    Check your JSON, that error would be because it's invalid/formatted incorrectly.
  • h

    Hazard

    04/09/2022, 9:13 PM
    True, if its actually wrong creds, then its not json, should fix that
  • h

    Hazard

    04/09/2022, 9:19 PM
    Alright, no more cors errors, thanks
  • s

    Stew

    04/10/2022, 12:13 PM
    @Isaac McFadyen | YYZ01 Pinging you just because we were discussing it yesterday, and a small update in case anyone else wants to utilize the cloudflare cdn in front of their pages application for dynamic pages/functions. If you put a worker in front of the pages project and use that to handle every request to it, you can use the
    cacheEverything
    & `cacheTtl `https://developers.cloudflare.com/workers/runtime-apis/request/#requestinitcfproperties properties to store the results of that request in the cdn, rather than worker cache. (So cache status shows MISS/HIT instead of dynamic) Pros Can utilize cdn tiered cache to get more cache hits Reduced load on external downstream systems (db/external apis) Save costs if a function has a long runtime Can invalidate cdn globally using the api, compared to the worker cache where you can only create/delete from the workers cache in the data centre the request is being run in. Cons Not worth doing if your page is lightweight Lose control of cdn/cache duration on function level, this is controlled at the worker level now (eg even if function has cache-control private, it will be cached if the worker sets it to be cached) The function can't return headers that would store it in cache, as it will go to the workers cache as well. So you need to know before sending the request to the function whether the result should be cached (eg path, presence of a header/cookie etc) You'll always run a worker for every request, there's no way to have the CDN in front of the worker which could be done if you used an external origin (tradeoff which imo is worth it due to how cheap workers are). More complicated CORS/host setup.
  • t

    travtrax

    04/10/2022, 5:26 PM
    ~~I have a pages sveltkit deployment e.g. newcoolpage.pages.dev I'm hoping to use pages to incrementally replace an existing site's paths with pages-based versions. e.g. my-current-site.com/oldcoolpage is replaced with newcoolpage.pages.dev I can't seem to add a path-based url as a custom domain for a pages, so I set up a worker (e.g newcoolpage-proxy.workers.dev) and added my-current-site.com/oldcoolpage as a trigger and it simply responds with a fetch of newcoolpage.pages.dev. If it hit the default worker's trigger the whole thing works beautifully but if I browse to the custom trigger I evenutally get a 522 Time Out from cloudflare... any ideas??? Worker logs actually don't even show hits when calling the proxied url my-current-site.com/oldcoolpage, but I do get logs hitting the default worker trigger.~~ I figured it out... I was using *.my-current-site.com/oldcoolpage... e.g. the preceeding dot was the issue.
  • h

    Hazard

    04/11/2022, 1:18 AM
    is it possible to add headers after middleware next()?
  • e

    Erwin

    04/11/2022, 1:21 AM
    Yeah.. should be possible indeed. If I remember correctly the return value of next() is a Response right?
  • h

    Hazard

    04/11/2022, 1:21 AM
    yeah, i was adding a header but it was null, now i realized it's probably an error from my end
  • s

    simpson

    04/11/2022, 10:55 AM
    We are trying to build a function to invoke Direct Creator Upload but are getting a CORS error, any tips on how did it? We don't have any issues with it on Workers
  • s

    Seb

    04/11/2022, 3:54 PM
    I can't seem to access the public folder in a Functions-project; is this a design decision, or did I perhaps do something wrong? can't seem to access
    {HOST}/favicon.ico
    or
    {BASE_DOMAIN}/public/favicon.ico
    or
    {BASE_DOMAIN}/static/favicon.ico
    Copy code
    .
    ├── functions
    │   └── [[path]].ts
    └── public
        ├── favicon.ico
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 3:54 PM
    How are you trying to access them?
  • s

    Seb

    04/11/2022, 3:55 PM
    not through some API, just browsing through Firefox
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 3:55 PM
    I believe you need to explicitly return the static asset from your Function using
    context.next()
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 3:56 PM
    (which gets the associated static asset for the request)
  • s

    Seb

    04/11/2022, 3:56 PM
    ohhhh, I see thanks! the assets need to be stored on Workers KV, right? so I'd need some kind of build step as well, I assuem
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 3:56 PM
    Because your Function is a catch-all it's intercepting everything.
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 3:56 PM
    And no, if you are using Pages it'll automatically store the static asset.
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 3:57 PM
    Just make sure your build output directory is set to
    public
    if you want to access things in
    public
  • s

    Seb

    04/11/2022, 4:02 PM
    thanks, @Isaac McFadyen | YYZ01 it was the catch all pretty neat, I love functions! very simple layout
  • s

    Skye

    04/11/2022, 4:02 PM
    I'm trying to use the
    PagesFunction
    type from @ cloudflare/workers-types in my function, but I'm not sure how to use it correctly? There doesn't appear to be a way to type an entire function
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 4:03 PM
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 4:03 PM
    Not Cloudflare 😆
  • s

    Skye

    04/11/2022, 4:03 PM
    (sorry that did not mean to ping)
  • s

    Skye

    04/11/2022, 4:04 PM
    Unsure if I'm using it wrong or not
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 4:04 PM
    I think it might go after the )?
1...116117118...392Latest