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

    Isaac McFadyen | YYZ01

    04/11/2022, 4:04 PM
    Not sure 😄
  • s

    Skye

    04/11/2022, 4:04 PM
    That indicates a return type
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 4:05 PM
    Yeah but what you have now indicates input params
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 4:05 PM
    Not sure how to type the whole thing tbh 🤷‍♂️
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 4:05 PM
    Oh wait.
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 4:05 PM
    It's a const, right?
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 4:05 PM
    Can you type the const?
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 4:05 PM
    so export const onRequestGet: PagesFunction = ...
  • s

    Skye

    04/11/2022, 4:06 PM
    Oh that's it! Perfect thanks
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 4:06 PM
    Great 🙂
  • s

    Skye

    04/11/2022, 4:06 PM
    Now just to work out how to type this haha
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 4:07 PM
    Whew...
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 4:07 PM
    😅
  • i

    Isaac McFadyen | YYZ01

    04/11/2022, 4:07 PM
    No clue, sorry 😆
  • s

    Skye

    04/11/2022, 4:07 PM
    I'll work it out, thanks anyways
  • j

    Jake Casto

    04/11/2022, 4:11 PM
    Copy code
    declare global {
      const clientID: string
    }
    should work
  • s

    Skye

    04/11/2022, 4:14 PM
    Not for when you're using functions, that comes under env.clientID, not the global clientID variable
  • j

    Jake Casto

    04/11/2022, 4:15 PM
    Then wrap clientID in
    env {}
    for that type--I am not familiar with Pages but have to do this in Workers TS projects.
  • j

    Jake Casto

    04/11/2022, 4:16 PM
    If it is mimicking node's
    process.env
    then you must
    Copy code
    declare global {
      namespace NodeJS {
        interface ProcessEnv {
          clientID: string
        }
      }
    }
  • s

    Skye

    04/11/2022, 4:17 PM
    It's not node's env but that snippet might let me work out how to solve it
  • s

    Skye

    04/11/2022, 4:27 PM
    Ended up creating my own type which does the trick. Thanks all
  • z

    zachlankton

    04/12/2022, 4:06 AM
    Hello everyone! Playing around with pages and functions... sorry if this is a noob question, but please point me in the right direction. How can I work with functions locally? Does wrangler work for this? What command? I tried wrangler dev script, but i get an
    Unexpected token 'export'
    error. Please and thank you in advance!
  • h

    HardAtWork

    04/12/2022, 4:26 AM
    https://developers.cloudflare.com/pages/platform/functions/#develop-and-preview-locally
  • z

    zachlankton

    04/12/2022, 4:31 AM
    hmmm, weird, I tried that earlier and it didn't work, but now its working!
  • z

    zachlankton

    04/12/2022, 4:31 AM
    Thanks!
  • a

    alinador

    04/12/2022, 7:53 AM
    Hi guys, Middleware: passing a URL to the next function works locally, but not after deployment. I am trying to rewrite URLs based on country and device (using functions, I want to mimic the page transform rule rewrite) Why do we have an option to pass a new url to the next function if it ignores and we get the original response? @Walshy | Pages
  • j

    JustinNoel

    04/12/2022, 10:46 AM
    You would type it like this:
    Copy code
    export type APIEnv = {
        ADMIN_KEY: string;
        DEV: string;
        KV_LAUNCHING: KVNamespace;
    }
    
    type Params = "key" | "fname" | "lname";
    
    export type MiddlewareData = {
        logs?: string[];
    };
    
    export const onRequestGet: PagesFunction<
        APIEnv,
        Params,
        MiddlewareData
    > = async ({ env, params, request, data }) => {
      ...
    }
    The APIEnv, Params, MiddlewareData can be named anything you like of course.
  • s

    Skye

    04/12/2022, 10:58 AM
    that's so useful! Thanks so much <3
  • s

    Skye

    04/12/2022, 10:58 AM
    would love for that to be documented
  • z

    Zeraph

    04/13/2022, 3:43 AM
    I have an idea of making use of functions, but I'm not sure whether it is possible to implement. I have a webpage deployed on Cloudflare Pages. In it, there is a HTML Form. My idea is to create a function to handle the form submission (POST request) and then send an email to my personal mail box (or the one under my Cloudflare domain) for every new form submission. I believe the first part is easy but I'm not sure about the send email part. Is it possible? Please tag me on this
1...117118119...392Latest