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

    Subh

    12/09/2021, 11:16 AM
    So that basically giving me the folders. Not really running the APIs
  • s

    Subh

    12/09/2021, 11:16 AM
    Must specify a directory of static assets to serve or a command to run.
  • g

    geelen

    12/09/2021, 11:16 AM
    ah yes,
    ./dist
  • g

    geelen

    12/09/2021, 11:16 AM
    assuming that's where the rest of your app is built
  • s

    Subh

    12/09/2021, 11:17 AM
    but I dont have a dist right?
  • s

    Subh

    12/09/2021, 11:17 AM
    Cause I am trying to run the functions
  • g

    geelen

    12/09/2021, 11:18 AM
    yeah it's a bit backwards, sorry. You can just specify
    .
    if you're just interested in running your functions
  • g

    geelen

    12/09/2021, 11:18 AM
    but it's designed to replicate what happens when you deploy, which is that your functions run in front of your assets
  • g

    geelen

    12/09/2021, 11:18 AM
    so you have to specify your assets to run
    pages dev
  • s

    Subh

    12/09/2021, 11:18 AM
    functions/api/v1/hello.js
    this is file path. would
    api
    in a path create an issue as well?
  • s

    Subh

    12/09/2021, 11:22 AM
    didn't work 😦
  • g

    geelen

    12/09/2021, 11:25 AM
    shouldn't do, hmm
  • g

    geelen

    12/09/2021, 11:26 AM
    you're in the project root dir, yes?
  • s

    Subh

    12/09/2021, 11:33 AM
    Yes!
  • s

    Subh

    12/09/2021, 11:34 AM
    I see this
  • s

    Subh

    12/09/2021, 11:34 AM
    Ran
    npx wrangler@beta pages dev .
    on root
  • g

    geelen

    12/09/2021, 11:35 AM
    do
    /hello
    ?
  • g

    geelen

    12/09/2021, 11:36 AM
    ha! wrong port :)
  • g

    geelen

    12/09/2021, 11:36 AM
    8788
  • g

    geelen

    12/09/2021, 11:36 AM
    not
    3000
  • g

    geelen

    12/09/2021, 11:37 AM
    http://localhost:8788/api/v1/hello
  • g

    geelen

    12/09/2021, 11:37 AM
    the
    /functions
    bit is just where the functions live, it's not part of the url
  • s

    Subh

    12/09/2021, 11:41 AM
    Nope, I think something I am not doing right
  • s

    Subh

    12/09/2021, 11:41 AM
  • c

    chrisjmccreadie

    12/09/2021, 11:49 AM
    @Subh instead of. Use functions
  • g

    geelen

    12/09/2021, 11:49 AM
    everything looks right, what's the contents of your
    hello.js
    file?
  • c

    chrisjmccreadie

    12/09/2021, 11:49 AM
    That works for me
  • s

    Subh

    12/09/2021, 11:50 AM
    Copy code
    export async function onRequestPost(request) {
      return new Response(JSON.stringify(request));
    }
  • c

    chrisjmccreadie

    12/09/2021, 11:53 AM
    wrangler pages dev functions In browser go to http://127.0.0.1:8788/api/v1/hello/ Works for me everytime
  • s

    Subh

    12/09/2021, 11:54 AM
    So http://127.0.0.1:8788/api/v1/all
    Copy code
    export async function onRequest(context) {
      return new Response(JSON.stringify(context));
    }
    this works then http://127.0.0.1:8788/api/v1/hello
    Copy code
    export async function onRequestPost(request) {
      return new Response(JSON.stringify(request));
    }
    this doesnt work
1...353637...392Latest