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

    Skye

    12/22/2022, 11:13 AM
    Is this just for serving a 404 file?
  • l

    LoaiA

    12/22/2022, 11:14 AM
    no it would be for handling all requests that didn't find a static asset
  • l

    LoaiA

    12/22/2022, 11:14 AM
    in my case an ssr for sveltekit
  • l

    LoaiA

    12/22/2022, 11:15 AM
    but currently even the assets and pre rendered pages count towards the usage
  • s

    Skye

    12/22/2022, 11:15 AM
    You'd probably have to make an issue with sveltekit to get them to include prerendered pages in the _routes.json that they generate for you
  • l

    LoaiA

    12/22/2022, 11:16 AM
    there is an issue already but the main bottleneck is the 100 limit
  • l

    LoaiA

    12/22/2022, 11:16 AM
    thanks for your help really appreciate it @Skye
  • l

    LoaiA

    12/22/2022, 11:17 AM
    I am gonna make a suggestion for a 404.js function
  • l

    LoaiA

    12/22/2022, 11:17 AM
    seems pretty useful for these cases
  • s

    Skye

    12/22/2022, 11:17 AM
    I don't believe I've seen anyone ask for it before so it could be for sure
  • z

    zszszsz

    12/22/2022, 6:57 PM
    The current behavior, that it would respond
    index.html
    is for SPA routing. Most SPA practices change their path so that users can go directly back to the position where they leave.
  • z

    zszszsz

    12/22/2022, 7:00 PM
    I think you can always serve
    index.html
    or
    404.html
    first, and let JavaScript to request the actual content
  • z

    zszszsz

    12/22/2022, 7:03 PM
    Yeah this behavior is not very friendly for ssr though
  • z

    zszszsz

    12/22/2022, 7:09 PM
    I think maybe you can do it this way: let the function be
    /ssr/[[path]]
    , and have
    index
    and
    /
    redirect to
    ssr/index
  • z

    zszszsz

    12/22/2022, 7:10 PM
    or any other names that sounds reasonable
  • z

    zszszsz

    12/22/2022, 7:11 PM
    or have all static files in
    /static
    and exclude them in
    _routes.json
  • c

    Cоlе

    12/23/2022, 12:38 AM
    I just made a whole SSG thing that relies on
    import.meta.glob
    , but it never occurred to me that it wouldn't work when deployed
  • c

    Cоlе

    12/23/2022, 12:39 AM
    can anyone think of another way one might import/fetch/whatever all of the files in a folder?
  • s

    Skye

    12/23/2022, 12:46 AM
    You should use
    env.ASSETS.fetch("/path/to/my/asset")
    (returns a response)
  • s

    Skye

    12/23/2022, 12:47 AM
  • t

    tzul

    12/23/2022, 11:34 AM
    I am trying to use a v8-compatible library (date-fns). When importing it to my function, I get 'Cannot find module 'date-fns'. I do not get that error when importing it into a page. Based on what I can find, wrangler can be used to prepare the dependency for use, but I can't find doc on how. Any guidance?
  • k

    kian

    12/23/2022, 11:40 AM
    shouldn't be anything more than
    npm install date-fns
    and then just importing it in your Functions code
  • t

    tuf

    12/23/2022, 6:16 PM
    Is there any way to read a file from a function?
    Copy code
    - functions/
    - - index.ts
    - views
    - - index.view
  • t

    tuf

    12/23/2022, 6:16 PM
    Oh, I just read this
  • t

    tuf

    12/23/2022, 6:16 PM
    lol
  • s

    Skye

    12/23/2022, 6:26 PM
    It's worth noting that it'll have to be a file available in the uploaded assets
  • s

    Skye

    12/23/2022, 6:26 PM
    If you try to access something outside of that, it won't work
  • t

    tuf

    12/23/2022, 6:26 PM
    I might be wrong but it doesn't work on local env
  • s

    Skye

    12/23/2022, 6:26 PM
    Could you add more info?
  • t

    tuf

    12/23/2022, 6:27 PM
    Copy code
    TypeError
    Failed to parse URL from /users/hello/
    I tried several different paths
    users/hello, /users/hello, /users/hello.html, /functions/users/hello.html
    etc, all had this error
1...321322323...392Latest