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

    albedo

    12/05/2021, 4:56 PM
    Im trying to make an admin page for modifying settings stored in kv and since functions are now generally available I thought why not take advantage of that
  • n

    Nik

    12/05/2021, 6:53 PM
    @User yes the worker is in the functions folder. I only get the 404 page from my hugo site when I try to go to the functions path
  • c

    chrisjmccreadie

    12/05/2021, 7:26 PM
    are you sure it's a 404 and not an error with the worker. I saw in the forum you said you where using workers before. You have to code workers for pages slightly different than normal workers
  • t

    Tv

    12/05/2021, 9:52 PM
    is it possible to have two patterns like
    /functions/[foo]/[bar].ts
    ? i keep getting 404 and i'm not sure if it's my fault or not
  • t

    Tv

    12/05/2021, 9:52 PM
    "In turn, the URL segment(s) that match the placeholder will be available under the context.params object using the filename placeholder as the key." in docs implies yes, but it ain't working
  • g

    Greg Brimble | Cloudflare Pages

    12/05/2021, 9:53 PM
    Not presently. You'll have to do
    /functions/[[captureAll]].ts
    and parse out individual segments yourself unfortunately.
  • g

    Greg Brimble | Cloudflare Pages

    12/05/2021, 9:53 PM
    I've got a note to myself to look into adding support for multiple parameters like this, but haven't gotten around to it yet.
  • t

    Tv

    12/05/2021, 9:54 PM
    if you're on that,
    functions/blah-[x].ts
    would also be great. basically, steal SvelteKit routing 😉
  • t

    Tv

    12/05/2021, 9:54 PM
    (this really should exist as a library...)
  • m

    mike.pete

    12/06/2021, 12:00 AM
    Has anyone seen this error before? I'm trying to get functions working locally with create-react-app.
    Copy code
    TypeError: Web Socket request did not return status 101 Switching Protocols response with Web Socket
        at Server.<anonymous> (file:///C:/Users/mike/github/menu/front/node_modules/@miniflare/http-server/dist/src/index.js:553:22)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
  • e

    Erwin

    12/06/2021, 12:04 AM
    I have seen it before, but I can't remember exactly how I solved it.. can you list the exact command that you use to start running things locally?
  • g

    Greg Brimble | Cloudflare Pages

    12/06/2021, 12:06 AM
    https://discord.com/channels/595317990191398933/789155108529111069/916495399995465769
  • g

    Greg Brimble | Cloudflare Pages

    12/06/2021, 12:06 AM
    Sorry, WebSockets aren't supported right now, so you've got to do this little hack at the moment.
  • m

    mike.pete

    12/06/2021, 12:12 AM
    This is the command I'm using to run things:
    npx wrangler pages dev -- craco start
  • m

    mike.pete

    12/06/2021, 12:12 AM
    Thanks for the quick reply @User & @User!
  • m

    mike.pete

    12/06/2021, 12:15 AM
    I've updated things, and that fixed the error! But browsing to
    /api/test
    doesn't work :/
  • m

    mike.pete

    12/06/2021, 12:18 AM
    it should invoke /functions/api/test.js, but it looks like react router is snagging this request instead of letting cf handle things
  • e

    Erwin

    12/06/2021, 12:19 AM
    That greatly depends on how you configure your react-router yes.. very possible
  • e

    Erwin

    12/06/2021, 12:20 AM
    Problem is that they have like 3 versions of react-router and I have only really used v4, so I am not entirely sure how you would solve it
  • g

    Greg Brimble | Cloudflare Pages

    12/06/2021, 12:24 AM
    How are you requesting
    /api/test
    ?
  • m

    mike.pete

    12/06/2021, 12:26 AM
    oh gotcha, that makes sense. I'm using
    "react-router-dom": "^5.3.0"
    and they seem to be using
    "react-router-dom": "^6.0.1"
    in their example: https://github.com/cloudflare/images.pages.dev I'm not sure if the version would make that big of a difference Does react-router have a config file for this somewhere?
  • m

    mike.pete

    12/06/2021, 12:28 AM
    I'm just opening it in chrome. Everything works fine when I push things to CF, but it's not playing nicely in my local environment
  • m

    mike.pete

    12/06/2021, 12:28 AM
    /functions/api/test.js
    Copy code
    export const onRequest = () => {
      return new Response(new Date().toISOString())
    }
  • g

    Greg Brimble | Cloudflare Pages

    12/06/2021, 1:22 AM
    Sorry, I meant, what’s the client-side code that’s calling that?
  • m

    mike.pete

    12/06/2021, 1:40 AM
    there isn't any client-side code calling it right now, I'm just trying to get the test working, and then I'll start building out the frontend and backend 🙂
  • g

    Greg Brimble | Cloudflare Pages

    12/06/2021, 8:12 AM
    Ah, okay. I wouldn’t worry about React Router intercepting the request then. Any `fetch`es or whatever that you make should go straight to that endpoint.
  • r

    robinio

    12/06/2021, 9:03 AM
    Quick question regarding pages-functions pricing. I am planning on adding a rather small feature in a function and would like to use it at example.com/my_function, every other url should be default pages behaviour. Is every request against example.com counted as a function call that falls back to default resource serving or are only calls to /my_function billed?
  • g

    Greg Brimble | Cloudflare Pages

    12/06/2021, 9:04 AM
    In this beta, yes. We're hopeful that we'll be able to be smarter about that before we GA and start charging.
  • g

    Greg Brimble | Cloudflare Pages

    12/06/2021, 9:05 AM
    (Yes to "every request against example.com counted as a function call")
  • r

    robinio

    12/06/2021, 9:07 AM
    Ok thanks, that's how I understood the current documentation and wondered if this is really the case. At least for me that would be blocker to enable pages-functions to prod and would keep my workers split from pages.
1...313233...392Latest