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

    richardcooke

    02/10/2022, 12:50 PM
    🙏 amazing
  • g

    geelen

    02/10/2022, 12:54 PM
    > The reason this is an issue for us currently is how our auth cookies currently work (we can't authenticate on a pages.dev domain). Yeah I would set up a catch-all proxy router on a wildcard subdomain and pass through to the pages.dev site there
  • r

    richardcooke

    02/10/2022, 12:57 PM
    thought this would be the answer, thanks for the speedy replies
  • k

    Kim

    02/10/2022, 1:34 PM
    Is there any way to add type definitions for Page Functions in JavaScript? Since we're exporting functions and not importing anything, there's no types. Here's how SvelteKit does it:
    Copy code
    js
    /** @type {import('@sveltejs/kit').RequestHandler} */
    export async function get({ params }) {
        // `params.id` comes from [id].js
        const item = await db.get(params.id);
    
        if (item) {
            return {
                body: { item }
            };
        }
    
        return {
            status: 404
        };
    }
  • r

    Rubidot

    02/10/2022, 7:21 PM
    Thanks. I figured it should possible to access static assets, but it wasn't in the documentation. You gave me the push I needed to figure it out. This issue thread helped, and I'll add my findings to hopefully help others trying to do the same thing https://github.com/cloudflare/wrangler2/issues/165
  • e

    Erwin

    02/10/2022, 8:28 PM
    Certainly still a beta feature where there is a bunch that still need to be done. Like documentation and tutorials etc.
  • l

    Larry

    02/10/2022, 9:08 PM
    First-time poster here so excuse me if this is not the right place for this sort of question, but... Is there a way to do durable objects local development/testing using
    wrangler pages dev
    ? I know you can bind DOs when you launch
    wrangler pages dev
    and I'm guessing that the state is actually stored in memory locally, but the actual code for the DO class comes from the code you've previously deployed. I'm hoping for an experience like
    ./functions
    folder which gets automatically "compiled" and served up locally. Maybe stuff in the
    ./durable_objects
    folder is similarly automagically handled. If not, is there some other way or are we stuck publishing our DO even before we can use it locally? When I look at the miniflare docs which
    wrangler pages dev
    is wrapping, it looks like it's possible either via the JS API or maybe even with the
    script
    field in the wrangler.toml file. I'd rather not use miniflare directly if it can be helped but I'm ready to start exploring that if nobody else knows how to do it with wrangler directly.
  • e

    Erwin

    02/10/2022, 9:10 PM
    This is absolutely the right place! @User, what is the latest guidance on this?
  • k

    kmiyashiro

    02/11/2022, 1:00 AM
    Is there any way to see which functions are getting called? I have a svelte-kit pages project that shouldn't be using functions, but maybe the framework auto-generates SSR functions? I see the function calls going up quite a bit on the project page and was wondering how that was happening.
  • i

    Isaac McFadyen | YYZ01

    02/11/2022, 1:20 AM
    Currently all assets, even static assets, generate a function request. Pages Functions are still in beta and this is planned before it hits GA, but in the meantime if you need a higher request quota you can request it here: https://discord.com/channels/595317990191398933/910978223968518144/912483697540866118
  • k

    kmiyashiro

    02/11/2022, 1:22 AM
    ah.. I see
  • k

    kmiyashiro

    02/11/2022, 1:22 AM
    Is that specific to svelte or is it for all pages?
  • k

    kmiyashiro

    02/11/2022, 1:22 AM
    (the "every asset is a function request")
  • i

    Isaac McFadyen | YYZ01

    02/11/2022, 1:23 AM
    All Pages Requests that use a _worker.js Function (which Svelte-Kit does internally).
  • i

    Isaac McFadyen | YYZ01

    02/11/2022, 1:26 AM
    If you used the
    @sveltejs/adapter-static
    then it wouldn't use Functions and you wouldn't hit that limit, but then you would have to prerender everything in advance (all
    loader
    functions or
    endpoints
    are called once on build).
  • k

    kmiyashiro

    02/11/2022, 3:50 AM
    got it
  • k

    kmiyashiro

    02/11/2022, 3:50 AM
    I'll try it out
  • e

    Erwin

    02/11/2022, 4:44 AM
    Not just those. Even if you have only 1 function on 1 url, all your requests are counted as function invocations (although not billed and you can ask to increase the limit) Once they are coming out of beta you won’t be charged for any requests that only retrieve a static asset
  • h

    HardAtWork

    02/11/2022, 5:05 AM
    Something else I was wondering about: if a route might be server-side rendered, or just served statically depending on certain conditions, would the conditions where it isn't SSRed count as an invocation, since it is technically performing some kind of logic on the Function?
  • e

    Erwin

    02/11/2022, 5:13 AM
    Obviously nothing has been finalised yet, so everything can change and we don't know exactly how things are going to work. But the idea is that if you want to run any logic, that would count as an invocation. And if you are happy to just serve the static asset, you should not be charged. So your example would almost certainly be considered a function invocation.
  • j

    JustinNoel

    02/11/2022, 6:24 AM
    I'm not really familiar with doing that like your example. However, the pages functions types are here. https://github.com/cloudflare/workers-types#install
  • l

    Larry

    02/11/2022, 5:45 PM
    Ping. Any help here would be greatly appreciated.
  • t

    Trash Panda

    02/11/2022, 7:26 PM
    I'm having trouble getting the hello world example to work I think I configured right
  • e

    Erwin

    02/12/2022, 12:02 AM
    env.ASSETS.fetch(request)
  • u

    !!!chup

    02/12/2022, 4:57 AM
    Hello, could you please share us the source code of how you use Pages Functions to inject
    <meta>
    tags to your webpages?
  • u

    !!!chup

    02/12/2022, 4:58 AM
    Thanks in advance:)
  • e

    Erwin

    02/12/2022, 6:50 AM
    I don't have an extensive example handy, but you would use HTMLRewriter to do it: https://developers.cloudflare.com/workers/runtime-apis/html-rewriter
  • c

    Cоlе

    02/12/2022, 10:50 PM
    I figured it out. If you do
    http:
    it redirects all
    POST
    requests to
    GET
    , but not if you're using
    https:
    .
  • c

    Cоlе

    02/12/2022, 10:51 PM
    I don't imagine that's intended...?
  • e

    Erwin

    02/13/2022, 3:10 AM
    It has been a while since I read the specs, but I am reasonably sure that is exactly what is intended in the spec for a redirect.
1...757677...392Latest