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

    Isaac McFadyen | YYZ01

    03/21/2022, 12:25 PM
    ?pages-node-version
  • h

    Helpflare

    03/21/2022, 12:25 PM
    By default Pages builds use an old Node.JS version. To make sure it's using a specific/new version, add either: - An environment variable with a name of
    NODE_VERSION
    and a value of the version you want the build to use (for example,
    16
    ). - A file in your root directory called
    .node-version
    (notice the dot) and contents of your wanted version (for example, `16`; there's no other content, just the version). If a specific version doesn't work for you (for example,
    16.14.2
    ) try a less specific version (like just
    16
    ).
  • s

    Stigin

    03/21/2022, 12:25 PM
    just #beta things
  • i

    Isaac McFadyen | YYZ01

    03/21/2022, 12:26 PM
    Yeah. There are plans to move to a new build image eventually but don't know how soon that is.
  • s

    Stigin

    03/21/2022, 12:26 PM
    I think some of the Cloudflare pages docs need a serious update as well in general.
  • s

    Stigin

    03/21/2022, 12:27 PM
    esp the Svelte Site one.
  • s

    Stigin

    03/21/2022, 12:27 PM
    Anyway - all good thanks again Isaac.
  • u

    .Netcoredeveloper

    03/21/2022, 7:37 PM
    can anyone help me i am facing this error on Cloudflare.
  • u

    .Netcoredeveloper

    03/21/2022, 7:38 PM
    i am using the next.js
  • i

    Isaac McFadyen | YYZ01

    03/21/2022, 7:52 PM
    This isn't a Cloudflare issue, I'd take a look at your Next.JS
    getStaticProps
    to find where you are accessing
    mentor.avatar_url
  • i

    Isaac McFadyen | YYZ01

    03/21/2022, 7:52 PM
    Also, just a heads-up that Next.JS is only supported for static building in case you weren't aware. No SSR support yet.
  • k

    kristian

    03/21/2022, 8:05 PM
    filing issues appreciated! github.com/cloudflare/cloudflare-docs
  • k

    kristian

    03/21/2022, 8:05 PM
    we do review new tickets on a regular basis (literally just did this a few hours ago)
  • r

    rishav

    03/21/2022, 8:57 PM
    I am trying to build a vanillajs server app on Pages. My app generates a html for every route. My problem is that the static assets folder doesn't seems to have a fixed location. instead the static assets seem to become a child of the current route. For example; my css files are in a pub folder and I am adding it to my html as such;
    Copy code
    export async function buildHeaders() {
        return /*html*/`
            <head>
                <meta charset="UTF-8">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <link href="./pub/style.css" rel="stylesheet">
            </head>
        `;
    }
    when I goto
    localhost:8788
    my app is able to serve the style.css file. but if i goto, say,
    localhost:8788/posts
    , it tries to serve
    localhost:8788/posts/pub/style.css
    , which obviously doesn't exists. How can I give a permanent location for my static files?
  • s

    Skye

    03/21/2022, 8:59 PM
    you should remove the
    ./
    from that link and replace it with a
    /
  • s

    Skye

    03/21/2022, 9:00 PM
    ./ means it's relative to the current page's URL - / means the root of the site
  • r

    rishav

    03/21/2022, 9:01 PM
    Thanks! feeling pretty dumb after that explanation, but learned something new today 😅
  • r

    rishav

    03/21/2022, 9:36 PM
    Another question. I am trying to add a root level middleware in my functions directory to handle statuc assets on all my routes;
    Copy code
    // functions/_middleware.js
    const assetHandler = async (context) => {
        const url = new URL(context.request.url);
        console.log(url.pathname)
        if (url.pathname.startsWith('/pub/')) {
            return await context.next();
        }
    };
    export const onRequest = [assetHandler];
    However now on all my routes, I am getting an error
    Copy code
    [pages:err] GET /posts/13: TypeError: Cannot read properties of undefined (reading 'status')
        at next (C:\Users\risharan\node_modules\wrangler\pages\functions\template-worker.ts:112:50)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
    What am i doing wrong?
  • b

    Bytesource

    03/22/2022, 2:17 AM
    Thanks for the suggestion. I DM'd @User a few days again, but haven't got an answer yet. I wonder if uploading Typescript files to Cloudflare Pages (instead of only using Typescript locally, but uploading JavaScript) is not a common practice. Because if it was, importing one
    .ts
    file into another one would probably work (as it does locally). Anyway, I haven't been able to find any information whatsoever on my issue.
  • i

    Isaac McFadyen | YYZ01

    03/22/2022, 2:44 AM
    Reposting this here. Quick comparison between Functions and Workers at the moment. Workers - No built-in CI deployments (self-hosted CI only, and no deployment URLs or rollbacks), only supports CLI or Dashboard. - You can pay for more requests (100k free per day). - Gives the most control over bundling (bring your own
    esbuild
    , Webpack, Rollup, etc). - Logs can be viewed from wrangler or from the dashboard. Functions - CI deployments via GitHub or GitLab (no others supported at the moment). - Currently in beta, which means limited to 100k per day (you can't pay to get more, although you can fill out this form: https://docs.google.com/forms/d/e/1FAIpQLSe4N0BjIxu9AuissCAtYjXUovViXmdx2zopjzASaJi_SImJsw/viewform?usp=send_form). - No logs at the moment, although they are planned for General Availability. - File-based routing system. It can be overriden for more advanced cases and for bring-your-own routing libraries such as
    itty-router
    . - Can call
    next()
    to get the static asset with the same name as the incoming request. Same limitations as Pages apply (25mb max size, 20k max number of static assets). - Some frameworks support SSR for Functions (including but not limited to Remix, SvelteKit, and Nuxt so far).
  • s

    scsin

    03/22/2022, 12:55 PM
    Hi! Anybody has any examples for postgres with functions? I did find an example with workers using wasm
  • i

    Isaac McFadyen | YYZ01

    03/22/2022, 1:04 PM
    What do you mean by Postgres? There's likely not any way to host it on Functions (or Workers) itself, because: 1. Functions (and Workers) don't support TCP connections, only HTTP. 2. Functions are stateless and can't run stateful applications.
  • i

    Isaac McFadyen | YYZ01

    03/22/2022, 1:05 PM
    If you mean connecting to a Postgres database, it's currently being planned for the future but right now it's not possible because of 1.
  • s

    scsin

    03/22/2022, 1:09 PM
    Sorry! I meant connecting to a Postgres database. I'm running cloudflared with postgres + pgbouncer on my server. https://github.com/cloudflare/worker-template-postgres that's for workers but I wanted to know if there is an easier way to make it work, I'm not a big fan of using wasm in a serverless function
  • i

    Isaac McFadyen | YYZ01

    03/22/2022, 1:11 PM
    That demo only works if you have control of the Postgres instance and can set up Cloudflare Tunnel on it. And I don't think there's a non-WASM version yet, no.
  • s

    scsin

    03/22/2022, 1:12 PM
    Thanks!
  • s

    simpson

    03/22/2022, 1:21 PM
    Are there any sample apps built with functions yet? It would be cool to have a todo app or blog built on function to see how it works
  • w

    warflash

    03/22/2022, 1:41 PM
    Wait nuxt already supports ssr via functions? Couldnt find anything about that when searching for that recently 🤔
  • i

    Isaac McFadyen | YYZ01

    03/22/2022, 1:46 PM
    Yeah it does, I've seen a couple people using it.
  • i

    Isaac McFadyen | YYZ01

    03/22/2022, 1:48 PM
    It's very similar to this I think?
1...106107108...392Latest