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

    monad

    01/21/2023, 6:21 AM
    I don't have experience with Angular. But deployed NextJS and other React apps on Pages with Functions. So is your Api routes going to be deployed as Functions?
  • w

    William.

    01/21/2023, 6:22 AM
    No I only have a middleware to alter HTML on specific routes to include custom meta tags (as my angular is build in statics) for SEO reasons
  • m

    monad

    01/21/2023, 6:22 AM
    I've gone through the doc I shared. It looks like it's assuming it's just front end only app.
  • w

    William.

    01/21/2023, 6:23 AM
    Why would it work in wrangler then
  • m

    monad

    01/21/2023, 6:24 AM
    Usually how it's working for other frameworks is people are building some sort of package (called like driver, bridge etc..) that bundles up backend, API portion of your application into Pages Functions for you.
  • m

    monad

    01/21/2023, 6:24 AM
    It looks like Angular doesn't have such one. (at least yet).
  • m

    monad

    01/21/2023, 6:25 AM
    I'd try to follow this doc first. https://developers.cloudflare.com/pages/platform/functions/ There are some good examples.
  • m

    monad

    01/21/2023, 6:26 AM
    Especially Routing page. I think you supposed to build
    _routes.json
    file etc?
  • k

    kian

    01/21/2023, 6:27 AM
    Assuming the
    functions
    folder is just client-side JS, Pages ignores any folder called
    functions
    that isn't using Pages' Functions
  • k

    kian

    01/21/2023, 6:27 AM
    https://github.com/cloudflare/wrangler2/issues/2240
  • w

    William.

    01/21/2023, 6:49 AM
    functions folder has a file named _middleware.js using Functions from the doc API reference (like onRequestGet), it works with wrangler without problem its just not working on my preview branch
  • w

    William.

    01/21/2023, 6:50 AM
    When I put in /dist it says it doesn't find any functions, and when I keep it at the root of my project I have this message :
    Compiled Worker successfully.
  • w

    William.

    01/21/2023, 6:51 AM
    Which, to me, would mean my function folder was found and compiled and ready to work but it just don't
  • t

    tomByrer

    01/21/2023, 3:16 PM
    Is there a "vs" webpage/blog post of Pages-functions vs Workers? I'm familiar to Workers, but been away from CloudFlare & missed all the excitement.
  • z

    zszszsz

    01/21/2023, 6:43 PM
    I think the biggest difference is pages functions are routed by path.
  • z

    zszszsz

    01/21/2023, 6:43 PM
    And you can just look at
    PageFunction
    type.
  • z

    ZøD?

    01/22/2023, 2:00 AM
    hey, has anyone been able to figure out a solution to hosting nextjs apps on workwrs? There seems to be an issur with the build sizes.
    • 1
    • 1
  • u

    Uxbert FE

    01/22/2023, 4:08 PM
    +1 We were trying to move some of our projects to CF, but the
    next-on-pages
    CLI output is huge, barely can host a 3-4 pages website. The CLI also has limitation, like: dynamic routes, redirections and Image component, etc... some of them has an open issue in Github for months. we hope to find some clarification about these aspects
  • t

    Thyrst

    01/23/2023, 2:08 PM
    Is anyone here using FaunaDB in typescript functions?
  • p

    Plotzes

    01/24/2023, 12:02 PM
    if I have a function that only handles POST requests, does a GET request on the same path count as a function invocation?
  • v

    Vero 🐙

    01/24/2023, 3:07 PM
    Hey @Plotzes , it would count as an invocation unless you specify POST as the method in _routes onRequestPost ,which results in GET returning a static asset instead of a function, but not sure if it’s billed as a function
  • p

    Plotzes

    01/24/2023, 3:37 PM
    ah thanks!
  • g

    Greg Brimble | Cloudflare Pages

    01/24/2023, 4:33 PM
    Yeah, unfortunately all filtering with
    _routes.json
    is path-only. You can't filter on the method, so any requests which match that path, regardless of method, will count as a billable invocation request.
  • p

    Plotzes

    01/24/2023, 4:34 PM
    yeah expected, but nice to get confirmation 👍
  • r

    rdutton

    01/25/2023, 2:18 AM
    I have combined separate pages and workers projects into a single pages+functions project employing _worker.js (advanced mode). Locally I have it working, but when I deploy, it ends with Error: Failed to publish your Function. Got error: Uncaught Error: No such module "itty-router". I'm struggling to find information on how to ensure dependencies are available to _worker.js in a pages/function context. The dependencies for the worker code are in package.json along with the the front-end dependencies, React in this case. This feels weird to me, but kind of makes sense. I can see the front-end code being built and uploaded, it's just worker. Do I have to add something to 'build' the worker? Any help appreciated!
  • i

    i40west

    01/25/2023, 3:01 AM
    _worker.js
    is used as-is, unless something has changed very recently. So you will have to bundle it with dependencies yourself, with esbuild or similar
  • r

    rdutton

    01/25/2023, 3:08 AM
    Thanks, please excuse my ignorance! Would I be doing that before deployment and checking the results into github. Or could the esbuild step happen within Cloudflare infrastructure?
  • i

    i40west

    01/25/2023, 3:09 AM
    Either way, really, it's up to you. In particular, if other people are going to be installing your app, then checking the build output into the repo means they don't need to worry about building it.
  • i

    i40west

    01/25/2023, 3:10 AM
    It's also probably easier to let it get checked in. I'm working on a Remix app and I do check in its output
    .js
    files
  • i

    i40west

    01/25/2023, 3:11 AM
    Hmm, I did end up putting a couple of them in .gitignore actually
1...338339340...392Latest