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

    Skye

    12/20/2022, 12:59 PM
    If you want it to be saved to the filesystem, you can add
    --persist
    too
  • s

    Skye

    12/20/2022, 12:59 PM
    And note that your local namespace will not be the same as your production one
  • w

    W7T2A

    12/20/2022, 1:41 PM
    Do the function deployment respect the kv_namespaces setting in wrangler.toml or how do I bind this in production?
  • l

    Larry

    12/20/2022, 6:27 PM
    You do this binding in the UI on Cloudflare for Pages. As far as I know wrangler.toml is ignored for Pages Functions.
  • p

    PaganMuffin

    12/20/2022, 6:46 PM
    Does Functions support Analytics Engine binding?
  • z

    zszszsz

    12/20/2022, 8:56 PM
    What is the best way for TypeScript to detect whether it is in browser or in the worker runtime ?
  • z

    zszszsz

    12/20/2022, 8:57 PM
    I was trying
    typeof origin === 'string'
    but it throws
    Error: Failed to get the 'origin' property on 'ServiceWorkerGlobalScope'
  • z

    zszszsz

    12/20/2022, 9:00 PM
    That seemed perfect though 😦
  • k

    kian

    12/20/2022, 9:04 PM
    navigator.userAgent === 'Cloudflare-Workers'
    if your compatibility date is newer than
    2022-03-21
    will identify Workers specifically
  • z

    zszszsz

    12/20/2022, 9:06 PM
    thanks
  • s

    skminhong

    12/21/2022, 5:09 AM
    Hi, I want to ask about local bindings. Is it the only way to bind KV namespaces or durable objects by using CLI arguments? Is there any plan to support
    wrangler.toml
    things for Cloudflare Pages? I guess this kind of question has already been asked much, but I'm new here 😅
  • j

    James

    12/21/2022, 5:28 AM
    Yes, and yes 😀 Support for config in some capacity is planned, such as wrangler.toml, but there’s no specifics or timeline yet as far as I know.
  • s

    skminhong

    12/21/2022, 5:30 AM
    Thanks!
  • j

    JohnsCreek

    12/21/2022, 7:57 AM
    Same here, never get functions work for a Pages project
  • a

    Arun_Venkat

    12/21/2022, 8:46 AM
    hi guys, i am not able to access KV locally? I am running wrangler using this command "wrangler pages dev -- npm run start --proxy=4000 --kv KV_Sample", but context.env.KV_Sample is coming undefined. Please help me with solution
  • s

    Skye

    12/21/2022, 8:54 AM
    duplicate of #874727019479437372
  • l

    LoaiA

    12/22/2022, 9:29 AM
    when using functions, will serving static assets still count to the usage? other question is what happens if a static asset and function have the same path. which one is served?
  • s

    Skye

    12/22/2022, 11:05 AM
    If your function is on a specific route such as
    /functions/hello.js -> /hello
    , you will only be billed for requests to /hello, regardless of whether there is an asset there or not, as the function takes priority
  • s

    Skye

    12/22/2022, 11:06 AM
    If you have one such as
    /functions/api/[[path]].js -> /functions/api/*
    , pages is unable to work out which routes you want your function to run on as easily, so any request under /api/* will rush your functions
  • l

    LoaiA

    12/22/2022, 11:08 AM
    ok for the assets question. if I have a static index.html at the base and functions for /api/[[path]] . will I also be billed for the
    index.html -> /
    requests
  • s

    Skye

    12/22/2022, 11:08 AM
    No, because pages knows you have no functions on that route
  • s

    Skye

    12/22/2022, 11:09 AM
    On the other hand, if you had
    /functions/[[path]] -> /*
    , it wouldn't know which routes are functions, and which aren't, so every request would be billed
  • l

    LoaiA

    12/22/2022, 11:09 AM
    is there a way I can make the static take priority
  • s

    Skye

    12/22/2022, 11:09 AM
    Unfortunately not
  • l

    LoaiA

    12/22/2022, 11:10 AM
    unless specified in _routes.json
  • l

    LoaiA

    12/22/2022, 11:10 AM
    but it only takes up to 100 entries
  • s

    Skye

    12/22/2022, 11:11 AM
    Yep
  • s

    Skye

    12/22/2022, 11:11 AM
    But that would entirely stop your function on that route, not just a serve the asset, or then the function if it's not there
  • l

    LoaiA

    12/22/2022, 11:12 AM
    I thought it would work like how a php website would work for example which it will try statuc assets first and if it doesn't find it it proxies the request to one index.php
  • l

    LoaiA

    12/22/2022, 11:13 AM
    it makes more sense to have static assets take priority or a bettwr solution would be a function 404.js
1...320321322...392Latest