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

    sovereignChai

    04/13/2022, 10:40 PM
    here for example
  • s

    sovereignChai

    04/13/2022, 10:40 PM
    Removing the headers fixed the problem: https://2968ff3a.listhq.pages.dev/
  • k

    kian

    04/13/2022, 10:41 PM
    To change response headers, you'd need to do
    const newResponse = new Response(response.body, response);
    and then modify/return
    newResponse
  • s

    sovereignChai

    04/13/2022, 10:41 PM
    Otherwise all I get is an opaque Cloudflare workers 1101 error in the error log
  • s

    sovereignChai

    04/13/2022, 10:46 PM
    @kian https://github.com/cloudflare/miniflare/issues/243
  • h

    HardAtWork

    04/14/2022, 12:58 AM
    Copy code
    js
    const myPostBody = await request.json();
  • k

    KZorro

    04/14/2022, 3:24 AM
    Hello folks, I'm working on my first pages site with functions. I just deployed my app and the worker is throwing an exception. Is there a way to go look at logs like there is in regular workers?
  • k

    kian

    04/14/2022, 3:25 AM
    Not with Functions at the moment.
  • k

    kian

    04/14/2022, 3:26 AM
    There's Miniflare but it's not 1:1 the behaviour of the Workers/Functions runtime so it might not be able to replicate the error locally
  • h

    HardAtWork

    04/14/2022, 4:23 AM
    You can also use a logger, like https://github.com/cloudflare/workers-honeycomb-logger
  • b

    btc10mm

    04/14/2022, 5:26 AM
    Using this on regular workers and enjoying the ability to debug/log with it
  • s

    Skye

    04/14/2022, 12:46 PM
    What's the best place to report a bug with functions routing? Is there a github issue place somewhere or just here
  • k

    kian

    04/14/2022, 12:47 PM
    Probably just here
  • i

    Isaac McFadyen | YYZ01

    04/14/2022, 12:47 PM
    I'm guessing it's been reported already, I remember a bug like that a while back, but drop it in here and we can escalate if it's not 🙂
  • i

    Isaac McFadyen | YYZ01

    04/14/2022, 12:47 PM
    (The team said they were looking into the other one)
  • s

    Skye

    04/14/2022, 12:50 PM
    The bug I found is when you have a
    [[param]].ts
    pattern, and an
    index.ts
    (which should route to the parent directory like /api/index.ts -> /api) file in the same directory, the ordering puts the param handler before the index handler, meaning your index handler will never be called, as the catch-all one is ordered first. This is applicable to both wrangler pages dev and compiling the function in production. I can see the compiled result showing the following to demonstrate this:
    Copy code
    js
    [...all previous routes here
      {
        routePath: "/api/:404*", // /functions/api/[[404]].ts
        method: "",
        middlewares: [],
        modules: [onRequest]
      },
      {
        routePath: "/api", // /functions/api/index.ts
        method: "",
        middlewares: [],
        modules: [onRequest2]
      }
    ]
  • s

    Skye

    04/14/2022, 12:52 PM
    I can drop a deploy ID if you need
  • s

    Skye

    04/14/2022, 12:56 PM
    (also relevant result from pages compiling it:)
  • i

    Isaac McFadyen | YYZ01

    04/14/2022, 12:59 PM
    I let the team know, thanks for the heads-up 🙂
  • r

    Ronan

    04/14/2022, 2:32 PM
    Hi I made a simple function in functions/![link].js ``export async function onRequestGet(context) { let originUrl = (new URL(context.request.url)).origin; if (context.params !== undefined) { if (context.params.link !== undefined) { let req = context.params.link; let link = await context.env.CfUrlShortener.get(req); if (link) { return new Response(null, { headers: { Location: link }, status: 301, }); } else { return new Response(null, { headers: { Location: originUrl }, status: 301, }); } } } return new Response("ERROR NO SHORT LINK PROVIDED", null, 2); }`` Routes are: ``{ "routes": [ { "routePath": "/!:link", "method": "GET", "module": [ "![link].js:onRequestGet" ] }, { "routePath": "/!:link", "method": "POST", "module": [ "![link].js:onRequestPost" ] } ], "baseURL": "/" }`` I bind my KV to CfUrlShortener in my Pages setting… It works perfectly with npx wrangler pages dev --kv CfUrlShortener -- npm run serve but when I deploy it I get a ``Error 1101 Ray ID: 6xxxxxxx3 • 2022-04-14 14:11:05 UTC Worker threw exception`` Is there anyway to get the error log ?
  • g

    Greg Brimble | Cloudflare Pages

    04/14/2022, 3:29 PM
    Do you have a deployed example of this not working? I think we actually evaluate this list bottom-to-top for modules.
  • s

    Skye

    04/14/2022, 3:32 PM
    https://b80c0b63.benny-link-shortener.pages.dev/
  • s

    Skye

    04/14/2022, 3:34 PM
    Or if you'd prefer build logs/etc
  • g

    Greg Brimble | Cloudflare Pages

    04/14/2022, 3:35 PM
    Oh, yeah, looks like something funky is going on. Single parameters work fine, but double parametered files seem to be taking precedence. Thanks for flagging, I'll take a look!
  • s

    Skye

    04/14/2022, 3:37 PM
    Np!
  • g

    Greg Brimble | Cloudflare Pages

    04/14/2022, 3:42 PM
    Ah, sneaky
    *
    is matching any number of parameters, including zero.
  • m

    morpheusfx

    04/14/2022, 3:45 PM
    Hi I use svelte-kit, and I want to export complicated OpenApi with a lot of routes (significantly more than 30, or even 100) but functionality itself is very simple server side, question: will Cloudflare deployer deploy all server side javascript as single "function" / "worker" (it should be much less than 1MB max allowed per worker) or will each be separate function, and how can i control that? if it is important i plan to use official NodeJS server API generator, but I am open to suggestions https://openapi-generator.tech/docs/generators/nodejs-express-server/ PS I know I can manually enter multiple routes in same svelte adapter, but I would really like to make use of OpenAPI generator to reduce chance of mistakes 🙂 Thank you in advance for help 🙂
  • s

    Skye

    04/14/2022, 3:47 PM
    So are you saying it's intended? Because it lets all other routes work first, and then is a catch-all, but specifically not /index routes
  • g

    Greg Brimble | Cloudflare Pages

    04/14/2022, 3:49 PM
    No, it's not intended. I was just realizing why it was a bug. Files which are more explicit (e.g. an exact match of
    /index.ts
    targeting
    /
    ) should take precedence over less explicit files (e.g.
    /[[path]].ts
    targeting
    /*
    )
  • s

    Skye

    04/14/2022, 3:49 PM
    Oh right
1...120121122...392Latest