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

    Erwin

    01/20/2022, 1:34 AM
    I would certainly start with Pages.. if you end up in a situation where you really can't do something, it isn't all that hard to switch to using worker sites for example later.
  • v

    velvetbaldmime

    01/20/2022, 7:26 AM
    Howdy! glad I have found this chat, as it answered some of my questions already (about lack of logging, for example) Is there any way to deploy to pages and workers in the following way: 1. I have a
    /.dist.sh
    2. Running
    ./dist.sh
    produces the following structure: -
    ./site
    -
    ./site/functions/....js
    -
    ./site/...html
    And I would like to deploy
    ./site
    to Pages. I tried to change the root - but then the
    ./dist.sh
    is not accessible, may be I should put
    dist.sh
    into
    ./site
    and just not clean that folder before generation But it seems wonky
  • c

    Cоlе

    01/20/2022, 8:12 AM
    how are you trying to run
    ./dist.sh
    ?
  • v

    velvetbaldmime

    01/20/2022, 8:13 AM
    I put
    ./dist.sh
    into the "Build command" of a Pages project
  • v

    velvetbaldmime

    01/20/2022, 8:13 AM
    (reason I'm doing this is because I'm deploy a Scala.JS function, so I need to build it first)
  • c

    Cоlе

    01/20/2022, 8:13 AM
    does your project use npm?
  • v

    velvetbaldmime

    01/20/2022, 8:14 AM
    nope, ./dist.sh just - bootstraps the tool I need to build the project - invokes it
  • v

    velvetbaldmime

    01/20/2022, 8:14 AM
    I could possibly do a dummy NPM project that just delegates to my build tool Is having NPM going to help somehow?
  • c

    Cоlе

    01/20/2022, 8:15 AM
    most likely, I'm not sure how exactly it works 🤔 but I'm doing the same thing on my project using npm and it works good
  • c

    Cоlе

    01/20/2022, 8:16 AM
    I'm generating files on the fly, only difference is I'm using a single .mjs file instead of .sh, so mileage may vary
  • c

    Cоlе

    01/20/2022, 8:17 AM
    in my package.json, I have
    npm run build
    as
    node build.mjs
    which just runs my js file
  • c

    Cоlе

    01/20/2022, 8:17 AM
    you might be able to do the same with a
    .sh
  • c

    Cоlе

    01/20/2022, 8:18 AM
    workers/pages filesystem is wonky
  • v

    velvetbaldmime

    01/20/2022, 8:18 AM
    and so you manage to 1. generate your functions in a folder that isn't checked in 2. successfully deploy pages app with functions in that folder?
  • c

    Cоlе

    01/20/2022, 8:18 AM
    yup
  • c

    Cоlе

    01/20/2022, 8:18 AM
    I have a folder that's not even real, it's a submodule
  • c

    Cоlе

    01/20/2022, 8:18 AM
    and I generate files and insert them into said folder
  • c

    Cоlе

    01/20/2022, 8:19 AM
    in terms of functions, I'm pretty sure it'd be more or less the same deal
  • c

    Cоlе

    01/20/2022, 8:19 AM
    could be wrong
  • c

    Cоlе

    01/20/2022, 8:19 AM
    it all happens at build time, before the function(s) are deployed
  • v

    velvetbaldmime

    01/20/2022, 8:20 AM
    Huh. I should spend more time on it then. For now I just 1. Build the functions on
    main
    2. Check them in into an orphan branch
    cloudflare
    under
    /functions
    subfolder 3. and I have Cloudflare Pages setup to work off of
    cloudflare
    branch, not
    main
    Which works for my purposes, but I miss all the preview environment and PR goodness
  • v

    velvetbaldmime

    01/20/2022, 8:20 AM
    Good to hear that it works for someone else, perhaps I will succeed as well 🙂
  • c

    Cоlе

    01/20/2022, 8:20 AM
    oh don't* bother with the branch or submodules
  • c

    Cоlе

    01/20/2022, 8:21 AM
    if you can get your build script to run as an
    npm run something
    , 99% chance it'll build on pages/workers
  • c

    Cоlе

    01/20/2022, 8:21 AM
    pages is mostly built for frameworks, so the "build command" part probably isn't meant to handle shell-type commands
  • c

    Cоlе

    01/20/2022, 8:22 AM
    but if you can pack it into a
    npm
    command, you're most likely a-ok
  • c

    Cоlе

    01/20/2022, 8:23 AM
    1s
  • c

    Cоlе

    01/20/2022, 8:25 AM
    here's part of my package.json:
    Copy code
    js
        "scripts": {
            "build": "node src/gendoc.mjs"
        },
    by running
    npm run build
    I'm just executing a script. You could probably do the exact same thing with a
    .sh
    file
  • c

    Cоlе

    01/20/2022, 8:25 AM
    "build": "./dist.sh"
    maybe?
  • v

    velvetbaldmime

    01/20/2022, 8:26 AM
    I'll give it a go - previously Pages wouldn't pick up
    functions
    folder that was generated by the script May be I messed it up somehow. That's really the only part that didn't work - dynamically generated functions as part of ./dist.sh The rest worked a-ok I'll see if running it as part of the NPM build makes a difference, thank you 🙏 The problem is most likely in the chair, not the computer..
1...656667...392Latest