Code Monkey home page Code Monkey logo

Comments (6)

dummdidumm avatar dummdidumm commented on September 13, 2024 1

What are you using platform for? It's only defined for edge functions, because its only member, context, is only available within edge functions (settable through the runtime adapter option). The only member of context is waitUntil, which you can now import directly in both edge and serverless functions: https://vercel.com/changelog/waituntil-is-now-available-for-vercel-functions

@Rich-Harris should we "shim" this for serverless, by passing along a "fake" context on which we provide the waitUntil method? I tend towards "no, use the package Vercel provides directly". If you're using platform you're already provider-specific.

from kit.

dummdidumm avatar dummdidumm commented on September 13, 2024 1

Ok, so the recommended approach is to import it from here import { waitUntil } from '@vercel/functions'?

Exactly

I'm not sure why, but I was under the impression that such thing should live on the "platform"

platform is more for things that are per-request and coming from the underlying platform. But yeah it's not very strict what's coming from where. In this case, since Vercel provides it, it's better to use the package directly.

For consistency it might even be better to remove it from edge functions? (deprecate with warning first, obvs)

Makes sense

from kit.

alexbjorlig avatar alexbjorlig commented on September 13, 2024

What are you using platform for? It's only defined for edge functions, because its only member, context, is only available within edge functions. The only member of context is waitUntil, which you can now import directly in both edge and serverless functions: https://vercel.com/changelog/waituntil-is-now-available-for-vercel-functions

@Rich-Harris should we "shim" this for serverless, by passing along a "fake" context on which we provide the waitUntil method? I tend towards "no, use the package Vercel provides directly". If you're using platform you're already provider-specific.

It was exactly waitUntil. Ok, so the recommended approach is to import it from here import { waitUntil } from '@vercel/functions'?

I'm not sure why, but I was under the impression that such thing should live on the "platform", but importing from @vercel/functions would also be ok.

from kit.

Rich-Harris avatar Rich-Harris commented on September 13, 2024

I tend towards "no, use the package Vercel provides directly"

I lean the same way - it would just add code to people's bundles if they weren't using it. For consistency it might even be better to remove it from edge functions? (deprecate with warning first, obvs)

from kit.

eltigerchino avatar eltigerchino commented on September 13, 2024

Isn't it already populated here?

export default async (request, context) => {
await initialized;
return server.respond(request, {
getClientAddress() {
return /** @type {string} */ (request.headers.get('x-forwarded-for'));
},
platform: {
context
}
});
};

The ambient type for it exists too although it's not correctly included when importing the adapter at the moment.
import { RequestContext } from './index.js';
declare global {
namespace App {
export interface Platform {
/**
* `context` is only available in Edge Functions
*/
context?: RequestContext;
}
}
}

Or am I mistaken and thinking of something entirely different?

from kit.

dummdidumm avatar dummdidumm commented on September 13, 2024

It's there, but it's only set for edge functions, not serverless functions, hence the confusion and thought to remove the context for edge, since it only contains waitUntil. Argument against it is that at some point in the future there might be other things on the context object and we would go adding it back in again - which makes me think we just leave everything as is and close this issue.

from kit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.