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

    syrokos

    03/16/2022, 12:45 AM
    If you are talking about allowed origins, you need to set up cors
  • a

    Angius

    03/16/2022, 12:46 AM
    No, not CORS, just the API needs me to whitelist servers that will be making requests to it
  • a

    Angius

    03/16/2022, 12:46 AM
    I'll try the header as you said
  • e

    Erwin

    03/16/2022, 12:58 AM
    https://www.cloudflare.com/en-au/ips/
  • a

    Angius

    03/16/2022, 12:58 AM
    Oh, nice, thanks!
  • b

    Bytesource

    03/16/2022, 9:22 AM
    Any idea why importing a typescript file into another typescript file fails? Can you successfully import
    ts
    files?
  • i

    Isaac McFadyen | YYZ01

    03/16/2022, 12:13 PM
    No, you can't import
    .ts
    files because by the time the import happens it's already a
    .js
    file. The only reason you can sometimes is because your bundler takes care of transforming it (Webpack or
    esbuild
    etc)
  • b

    Bytesource

    03/16/2022, 1:15 PM
    So, even though Cloudflare Functions support Typescript, in reality there an only be a single
    .ts
    file present because importing other
    .ts
    files is not possible? I tried importing a
    .ts
    file as
    .js
    into the main Typescript file, but this resulted in the same could not resolve… error. Is there a way to use Typescript natively (so to speak) with Cloudflare Pages?
  • i

    Isaac McFadyen | YYZ01

    03/16/2022, 1:15 PM
    I'm not sure, actually. I think it uses
    esbuild
    under the hood to bundle your functions, so
    .ts
    imports should absolutely work...
  • i

    Isaac McFadyen | YYZ01

    03/16/2022, 1:16 PM
    You might have to ask @User
  • d

    dsincl12

    03/16/2022, 1:50 PM
    Hi everyone, I just deployed a SvelteKit app on pages and added a simple API endpoint in functions/api/hello.js but now the site doesn't load anymore at all and returns 404 everywhere. What am I missing?
  • i

    Isaac McFadyen | YYZ01

    03/16/2022, 1:59 PM
    ?sveltekit-functions
  • h

    Helpflare

    03/16/2022, 1:59 PM
    SvelteKit doesn't work with functions since it uses them internally (meaning if you try to create functions it overrides theirs). Instead, try: - using SvelteKit endpoints. Anything you can do in Functions you can do in Endpoints. - using
    @sveltejs/adapter-static
    and normal Functions.
  • d

    dsincl12

    03/16/2022, 1:59 PM
    ty
  • d

    dsincl12

    03/16/2022, 3:17 PM
    anyone know how to access Cloudflare environment variables through SvelteKit endpoints?
  • i

    Isaac McFadyen | YYZ01

    03/16/2022, 3:20 PM
    Yup, sec. 🙂
  • i

    Isaac McFadyen | YYZ01

    03/16/2022, 3:20 PM
    https://github.com/sveltejs/kit/tree/master/packages/adapter-cloudflare#environment-variables
  • d

    dsincl12

    03/16/2022, 3:29 PM
    awesome then I was on the right track, ty very much
  • d

    dsincl12

    03/16/2022, 3:47 PM
    @User do I need to add the environment variable to interface Platform{} to get the value in app.d.ts as well?
  • i

    Isaac McFadyen | YYZ01

    03/16/2022, 4:07 PM
    Yup, that's exactly right. 👍
  • d

    dsincl12

    03/16/2022, 4:56 PM
    and then I access it with:
    Copy code
    export async function post({ request, platform }) {
        const data = await request.formData();
        const SENDGRID_API_KEY = platform.env.SENDGRID_API_KEY;
        ...
    can't understand why this value doesn't seem to exist 😦 is there something wrong in app.dt.ts?
    Copy code
    declare namespace App {
        // interface Locals {}
        interface Platform {
            env: {
                SENDGRID_API_KEY: SENDGRID_API_KEY
            }
        }
        // interface Session {}
        // interface Stuff {}
    }
  • i

    Isaac McFadyen | YYZ01

    03/16/2022, 4:56 PM
    If you're using
    svelte-kit dev
    unfortunately it doesn't have it.
  • i

    Isaac McFadyen | YYZ01

    03/16/2022, 4:56 PM
    You'll have to run
    svelte-kit build
    and then
    svelte-kit preview
  • i

    Isaac McFadyen | YYZ01

    03/16/2022, 4:57 PM
    (Which are mapped to
    npm run build
    and
    npm run preview
    I think)
  • d

    dsincl12

    03/16/2022, 4:57 PM
    ok but the env variable would be available in prod then?
  • d

    dsincl12

    03/16/2022, 4:57 PM
    everything seems to be correct?
  • i

    Isaac McFadyen | YYZ01

    03/16/2022, 4:59 PM
    Yeah, everything looks correct 👍
  • i

    Isaac McFadyen | YYZ01

    03/16/2022, 5:00 PM
    Oh, except that it should be
    string
    since that type is just the type.
  • i

    Isaac McFadyen | YYZ01

    03/16/2022, 5:00 PM
    So:
    Copy code
    interface Platform {
            env: {
                SENDGRID_API_KEY: string
            }
        }
  • d

    dsincl12

    03/16/2022, 5:00 PM
    aha,
    ${SENDGRID_API_KEY}
    would work?
1...979899...392Latest