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

    Walshy | Pages

    11/29/2022, 10:51 PM
    I'd recommend going to the #940663374377783388 channel
    m
    • 2
    • 1
  • y

    yusukebe

    11/30/2022, 5:45 AM
    Hi! I want to add Basic auth into the Next.js SSR project. Which way is easiest? With "Middleware" of Next.js? Addition, I want to use environment values, but I do not know how to use environment values in Next.js Middleware. Or can I use Pages Functions with Next.js??
  • y

    yusukebe

    11/30/2022, 5:46 AM
    I think the most certain way is to use additional Workers...
  • d

    DemosJarco

    12/01/2022, 11:02 PM
    What would be the ideal file structure to put classes referenced in a worker, but should not be directly routeable? Like
    file1.ts
    imports
    classA.ts
    and
    classB.ts
    but the class files should not be directly visitable, but
    file1.ts
    would be
    /file1
    . Will
    /functions/file1.ts
    be able to import from
    ../someFolder/classA.ts
    ?
  • i

    i40west

    12/01/2022, 11:36 PM
    Yes, I just make a /js folder or whatever in the project root
  • i

    i40west

    12/01/2022, 11:38 PM
    End up with like
    import Foo from '../../../js/bar.js';
  • j

    JustinNoel

    12/02/2022, 1:23 PM
    Same as i40west, but I use a
    utils
    directory.
  • d

    DemosJarco

    12/02/2022, 3:19 PM
    Oh ok. I was worried
    /functions
    was a hard cut off point for security reasons
  • g

    Ginie

    12/03/2022, 1:23 PM
    Hi. I am trying to upload a custom _routes.json so that page requests do not count towards limit. Since i added the _routes.json the deployments fail with following message
    Copy code
    14:21:28.114    Finished
    14:21:28.815    Compiled Worker successfully.
    14:21:28.865    Found _routes.json in output directory. Uploading.
    14:21:28.891    Validating asset output directory
    14:21:30.571    Deploying your site to Cloudflare's global network...
    14:21:32.191    Failed: an internal error occurred
    14:21:32.191    Error: Failed to publish assets. For support, join our Discord (https://discord.gg/cloudflaredev) or create a ticket and reference the deployment ID: 0f45070d-7f2b-4e5c-baa4-15ed3528d8bd
  • g

    Ginie

    12/03/2022, 1:24 PM
    and this is the
    _routes.json
    Copy code
    {
      "version": 2,
      "include": [
        "/api/*"
      ],
      "exclude": []
    }
  • k

    kian

    12/03/2022, 1:26 PM
    I don't think
    "version": 2
    is valid
  • g

    Ginie

    12/03/2022, 1:26 PM
    oh, dammit
  • k

    kian

    12/03/2022, 1:26 PM
    Should be
    1
  • g

    Ginie

    12/03/2022, 1:26 PM
    thank you very much
  • g

    Ginie

    12/03/2022, 1:29 PM
    think i misinterpreted the meaning of schema version and just bumped it, as i updated the pattern
  • k

    kleeut

    12/04/2022, 7:08 AM
    Hey team, I'm experiencing an issue with D1 bindings not getting recognised in a Pages Function, I assume I'm doing something silly. What I have works when running against the local server using wrangler but when I push it up to production the bound table appears to be missing on the
    env
    object. I've checked the binding names in the functions tab many times, both production and preview. When I dump the what's available on
    env
    I see properties called
    __D1_BETA_<database name>
    but these don't appear to have the
    prepare
    function on them (and the name implies they're not for me to use), when I add a new binding the new name appears with the same
    __D1_BETA_
    prefix. Does anyone have any ideas what I might be missing? It's worth noting that I'm using the Sveltekit adapter (https://www.npmjs.com/package/@sveltejs/adapter-cloudflare)
    s
    w
    h
    • 4
    • 7
  • s

    shadid12

    12/07/2022, 6:04 PM
    Hey all I created a tutorial on building global apps with pages functions. You can find it here 👇. Completely free. Let me know if you have any feedback. https://cloudflare.workshops.fauna.com/
  • b

    botato

    12/08/2022, 1:42 AM
    is it me or do environment variables just like, not exist (when accessed using process.env), even when set in the dashboard
  • b

    botato

    12/08/2022, 1:43 AM
    wait nvm, need https://developers.cloudflare.com/pages/platform/functions/api-reference/#envwithfetch
  • b

    botato

    12/08/2022, 1:49 AM
    hmm how is the context accessed from nextjs api routes?
  • b

    botato

    12/08/2022, 1:54 AM
    found
  • t

    TL&D

    12/10/2022, 6:14 AM
    I created an api of d1 using cloudflare pages functions and nuxt3. However, when using nuxt's useFetch/useAsyncData, a 404 page not found error comes as an api response. However, the response after hydration, rather than the SSR request, is normal. Does the functions of cloudflare pages work only in CSR, not SSR? Is wangler a simple happening in a development environment caused by running slower than nuxt?
  • e

    ElFitz

    12/10/2022, 10:48 AM
    Hello! I’ve been trying to use
    @cloudflare/pages-plugin-honeycomb
    . As a middleware it’s great, but has anyone had any chance with using the tracer’s fetch for requests? I’ve been trying to override ky’s (https://github.com/sindresorhus/ky) fetch with it, but without success.
  • d

    DatSparrow

    12/10/2022, 2:08 PM
    Is it possible for Cloudflare Pages Workers to have a scheduled task added (cron triggers or DO alarms)? Unless I'm missing something it does not look like there is anything about it in the Cloudflare Pages docs? Would I have to make a separate Cloudflare worker (which is less than ideal), or am I missing something obvious. Thanks 🙂
  • s

    Skye

    12/10/2022, 2:13 PM
    They unfortunately don't have a way to do that currently - you'll need a separate worker as you said
  • d

    DatSparrow

    12/10/2022, 2:14 PM
    Thanks for the help, what I expected :/
  • k

    konrad1221

    12/10/2022, 2:41 PM
    Hey - I am trying to migrate from Vercel to Cloudflare Pages with my project. I have enabled the edge-experimental but now it fails on
    Copy code
    % yarn build
    (...)
    info  - Creating an optimized production build  
    Failed to compile.
    
    ./node_modules/preact-render-to-string/dist/index.module.js
    Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime 
    Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
    
    Import trace for requested module:
    ./node_modules/preact-render-to-string/dist/index.module.js
    ./node_modules/next-auth/core/pages/index.js
    ./node_modules/next-auth/core/index.js
    ./node_modules/next-auth/next/index.js
    ./node_modules/next-auth/index.js
    
    ./node_modules/@babel/runtime/helpers/isNativeFunction.js
    Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime 
    Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
    
    Import trace for requested module:
    ./node_modules/@babel/runtime/helpers/isNativeFunction.js
    ./node_modules/@babel/runtime/helpers/wrapNativeSuper.js
    ./node_modules/next-auth/core/errors.js
    ./node_modules/next-auth/utils/logger.js
    ./node_modules/next-auth/core/index.js
    ./node_modules/next-auth/next/index.js
    ./node_modules/next-auth/index.js
    
    ./node_modules/@babel/runtime/regenerator/index.js
    Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime 
    Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
    
    Import trace for requested module:
    ./node_modules/@babel/runtime/regenerator/index.js
    ./node_modules/next-auth/core/errors.js
    ./node_modules/next-auth/utils/logger.js
    ./node_modules/next-auth/core/index.js
    ./node_modules/next-auth/next/index.js
    ./node_modules/next-auth/index.js
    
    
    > Build failed because of webpack errors
    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
  • s

    Skye

    12/10/2022, 2:43 PM
    It looks like
    preact-render-to-string
    (dependency of next-auth) relies on one of
    eval
    ,
    new Function
    or WASM to function- which isn't allowed in the edge runtime
  • k

    konrad1221

    12/10/2022, 2:51 PM
    I thought so, but docs says it should work on edge (https://next-auth.js.org/configuration/nextjs). Though on Vercel's edge. I am not really using SSR, only auth is on the edge, while rest is still static
  • s

    Skye

    12/10/2022, 2:52 PM
    I unfortunately don't know much about next auth - just explaining the error
1...315316317...392Latest