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

    sdev

    03/05/2023, 1:08 PM
    Use Node v16 and run
    npm add --no-save better-sqlite3
    . We need
    better-sqlite3
    to local dev D1. However, don't add
    better-sqlite3
    to
    package.json
    because Pages will try to install it on deployment which will throw an error.
  • s

    sdev

    03/05/2023, 1:09 PM
    and don't forget to seed your sqlite DB as the doc mentions.
  • s

    Skye

    03/05/2023, 1:11 PM
    None of that is anything to do with the error they're getting?
  • s

    Skye

    03/05/2023, 1:11 PM
    It's just that
    pages dev
    doesn't use your production database because it runs it locally with miniflare - meaning you'll need to make the table locally too
  • s

    Skye

    03/05/2023, 1:12 PM
    So you need
    --persist
    in your pages dev command to use the file system, not an in-memory database, and then
    wrangler d1 execute --local
    can help your create your tables locally
  • a

    Ariful

    03/05/2023, 8:43 PM
    thanks it worked
  • h

    hanpolo

    03/06/2023, 4:52 AM
    Does anyone have a guide or article on automated testing for functions. I'm using Jest.
  • l

    Larry

    03/06/2023, 1:00 PM
    I'm working on one. tl;dr; Use vitest or Jest with the miniflare plugin. https://miniflare.dev/testing/jest
  • l

    Larry

    03/06/2023, 1:07 PM
    However, since each Function is not a full worker, you have to load it and test it in isoation. Compose a Request Object -- the Jest-miniflare environment gives you that. Import your Function and call it's handler. It gives you isolated storage for KV, D1, and Durable Objects. If you have everything configured right,
    getMiniflareBindings()
    will give you the env parameter for your call to the handler. You'll have to compose your own params parameter for the handler call from your test.
  • l

    Larry

    03/06/2023, 1:08 PM
    There are a few more details, but that should be enough to get you started.
  • e

    eonicum

    03/06/2023, 2:19 PM
    Hi guys! I develop an e-commerce app with a payment gateway integration. At some point payment gateway sends payment status to the Cloudflare serverless function. But this request fails with the following error:
    code (ERROR): 403, Response: "error code: 1010"
    . Can somebody help me to resolve the issue?
  • h

    hanpolo

    03/06/2023, 3:31 PM
    Larry, thank you for the response. How close are you with the article? There are a bunch of questions on this. Do you have any code snippets, especially in Typescript?
    l
    • 2
    • 11
  • b

    bbong

    03/07/2023, 5:33 PM
    Hi everyone new here and having some problems with functions middleware. I have a file described but I can hit the endpoint without a log statement in the middleware firing. I tried different variations of directory structure and exports but nothing 😦
    s
    • 2
    • 3
  • a

    anujdeshpande

    03/07/2023, 6:55 PM
    So I have a function that works localy - i.e. when I run
    wrangler pages dev out
    but fails when I deploy to production. What's the best way to go about debugging this?
    s
    • 2
    • 9
  • w

    weide

    03/08/2023, 12:52 AM
    hi i'm new to pages. but i'm currently using next.js, is it better to move all apis into workers / functions ? currently, next.js defines api conventions. sometimes i can't tell whether i should use worker or use apis in nextjs. especially for those involves pure data access.
  • z

    zszszsz

    03/08/2023, 2:31 AM
    It is better to not use next.js with cf pages
  • i

    Isaac McFadyen | YYZ01

    03/08/2023, 12:45 PM
    That depends on your requirements. Cons:
    next-on-pages
    has some outstanding issues right now, and isn't given as much attention as e.g. someone like Vercel would. It works but it's not as integrated into the platform as competitors. Pros: Pages is free, and Functions pricing (what
    next-on-pages
    runs on) is much cheaper than competitors.
  • i

    Isaac McFadyen | YYZ01

    03/08/2023, 12:46 PM
    If you need more help making a decision you can look at the
    next-on-pages
    Github issues to see if any apply to you: https://github.com/cloudflare/next-on-pages/issues
  • h

    hanpolo

    03/09/2023, 2:01 AM
    Hi everyone. Is it possible to use _routes.json to specify a file extension that should be ignored. I'm trying to put my .spec.ts test files next to my functions.
  • a

    Ariful

    03/09/2023, 2:18 AM
    Hi, is there any way I can use remote mysql database with prisma?
  • h

    HardAtWork

    03/09/2023, 8:09 AM
    If a file in the Functions folder doesn't export
    onRequest
    ,
    onRequestGet
    ,
    onRequestPost
    , etc, it will be ignored.
  • z

    zszszsz

    03/09/2023, 10:18 AM
    Is it possible to custom esbuild options for functions ?
  • h

    HardAtWork

    03/09/2023, 10:27 AM
    Natively, only what is available on the CLI. Otherwise, you can invoke ESBuild yourself, and then use Advanced Mode
  • s

    sten

    03/09/2023, 2:53 PM
    Static pages are fine but SSR apps that rely on the nodejs eco-system is not supported today.
  • n

    nightshade427

    03/09/2023, 3:04 PM
    Are the preview bindings shared across all non-main branch prs? Is there a way to have different bindings in different prs, like having a different environment per pr much like workers can have multiple environments?
  • w

    Walshy | Pages

    03/09/2023, 3:33 PM
    Multiple envs are not supported today unfortunately
  • z

    zszszsz

    03/09/2023, 7:02 PM
    Or I can esbuild myself with
    bundle: false
    I think
  • n

    nightshade427

    03/10/2023, 12:31 AM
    Okay cool, thanks
  • k

    krsr

    03/10/2023, 1:46 AM
    any idea why I'd get a 405 when trying to hit a function defined with
    onRequestPost
    using a
    fetch()
    with method set to
    POST
    ?
  • w

    Walshy | Pages

    03/10/2023, 1:51 AM
    Sounds like you aren't hitting the function
1...355356357...392Latest