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

    Larry

    03/23/2023, 8:02 PM
    I can't speak to Astro but Vite is great and low config. It just seems to work. Also, there is vitest that will reuse your vite config. Cloudflare has published a miniflare plugin for vitest (along with a few other testing frameworks) that make Worker, Durable Object, KV testing super easy also.
  • s

    silentdevnull

    03/23/2023, 9:50 PM
    I'm getting the follwoing message in my build logs.
    Copy code
    Note: No functions dir at /functions found. Skipping.
    Page is setup for /output/wwwroot as the build page and I have the functions folder inside of that. Do I have the functions folder in the wrong spot?
  • w

    Walshy | Pages

    03/23/2023, 9:53 PM
    functions
    dir should be in the root
  • s

    silentdevnull

    03/23/2023, 10:05 PM
    root as in the output directory or root as the same level has the output directory
    Copy code
    /output/wwwroot
    /functions
    or
    Copy code
    /output/wwwroot
    /output/functions
    Thank you
  • m

    micromashor

    03/23/2023, 10:05 PM
    /functions
  • s

    silentdevnull

    03/23/2023, 10:36 PM
    Thank you, I changed my build script and now it working . Thank you both
  • h

    hanpolo

    03/25/2023, 8:01 AM
    Does anyone know how to do local development with functions and durable objects? Specifically how do you get binding with durable objects to work on a local environment?
    l
    • 2
    • 96
  • m

    My Account

    03/26/2023, 6:44 PM
  • m

    My Account

    03/26/2023, 6:44 PM
    why worker throw exception on this
  • m

    My Account

    03/26/2023, 6:44 PM
    it literally works fine in vanilla js
  • m

    My Account

    03/26/2023, 6:44 PM
    is there some other way to do this?
  • w

    Walshy | Pages

    03/26/2023, 6:46 PM
    ./?done isn't a valid URL
  • g

    GeorgeTailor

    03/26/2023, 6:46 PM
    is calling
    _middleware
    and another function, for example, `api/user`count as two calls in my account limit?
  • w

    Walshy | Pages

    03/26/2023, 6:46 PM
    One call (same worker, just 2 functions)
  • m

    My Account

    03/26/2023, 6:48 PM
    hmm it isn't is there any way I can just add query parameter to url
  • m

    My Account

    03/26/2023, 6:48 PM
    I mean I have multiple urls so I can't hardcode it
  • h

    HardAtWork

    03/26/2023, 6:50 PM
    This is a naive approach, but should work if you don't already have query params on your URL:```js return Response.redirect(req.url + "?done"); ```
  • m

    My Account

    03/26/2023, 6:50 PM
    oh thank you so much I forgot about this
  • w

    Walshy | Pages

    03/26/2023, 6:50 PM
    And the non-naive approach: url.search = '?done' return Response.redirect(url)
  • m

    My Account

    03/26/2023, 6:51 PM
    🌟
  • g

    GeorgeTailor

    03/27/2023, 11:46 AM
    is there any difference between doing
    import htmlTemplate from '../dist/resources/my-template.html
    and
    Copy code
    const url = new URL(context.request.url);
    const templateResult = await context.env.ASSETS.fetch(`${url.origin}/resources/my-template`);
    const template = await templateResult.text();
    in a Function?
  • g

    GeorgeTailor

    03/27/2023, 11:48 AM
    apart from typescript not complaining about the second one
  • h

    HardAtWork

    03/27/2023, 11:52 AM
    The first one bundles it into your Function, which will count towards the 1/5 MB size limit.
  • h

    HardAtWork

    03/27/2023, 11:53 AM
    It may be slightly faster
  • g

    GeorgeTailor

    03/27/2023, 11:53 AM
    ok, thanks
  • s

    silentdevnull

    03/27/2023, 5:03 PM
    With functions how supporting wasm. How would you use something like DO or D1 from inside of WASM. Is there away to call them directly or would you need to pass the data backout of WASM to call them in JS?
  • v

    Vero 🐙

    03/27/2023, 5:30 PM
    Hi @silentdevnull. Depends on what language you're using inside WASM. Our Rust library (
    workers-rs
    ) for example supports calling durable objects: https://github.com/cloudflare/workers-rs#durable-object-kv-secret--variable-bindings There is also an open issue for D1 support: https://github.com/cloudflare/workers-rs/issues/221
  • s

    silentdevnull

    03/27/2023, 5:36 PM
    I was planning on using C# as that what I know well and use everyday. I only started to learn rust a little.
  • v

    Vero 🐙

    03/27/2023, 6:08 PM
    @silentdevnull It should certainly be possible, but we don't maintain a library for C# WASM AFAIK so you may have to do a lot of stuff manually. The WASM ecosystem for Workers isn't as mature as non-Wasm (TypeScript/JavaScript) unfortunately
  • s

    silentdevnull

    03/27/2023, 7:58 PM
    Okay I do understand, it also hard to have options for every language. If I want to do more of it my self in C# would I just use the public api's or does the worker-rs do other thing in the background that isn't in the api's?
1...363364365...392Latest