kit icon indicating copy to clipboard operation
kit copied to clipboard

feat: support for `ServerlessFunctionConfig` and `EdgeFunctionConfig`

Open Smirow opened this issue 3 years ago • 1 comments

Adding support for :

  • memory, maxDuration and regions for Serverless Functions
  • envVarsInUse and regions for Edge Functions

I tried to keep the types structure defined here: https://vercel.com/docs/build-output-api/v3 without breaking the current API.

Limitation: settings cannot be defined on a by function basis when using split = true, they are applied globaly.

Maybe there is a nicer API for this, but for now:


import vercel from '@sveltejs/adapter-vercel';

export default {
  kit: {
    adapter: vercel({
      serverlessFunctionConfig: {
          memory: 1024,
          maxDuration: 10,
          regions: ['cdg1']
      },
    })
  }
};

and on the edge:


import vercel from '@sveltejs/adapter-vercel';

export default {
  kit: {
    adapter: vercel({
      edge: true,
      edgeFunctionConfig: {
          envVarsInUse: ['ENV1'],
          regions: ['cdg1']
      }
    })
  }
};

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • [ ] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • [X] This message body should clearly illustrate what problems it solves.
  • [ ] Ideally, include a test that fails without this PR but passes with it.

Tests

  • [X] Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • [X] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

Smirow avatar Jan 11 '23 14:01 Smirow

🦋 Changeset detected

Latest commit: 08842533c909b8046e2b9d1f0713e4517ab56cae

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/adapter-vercel Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Jan 11 '23 14:01 changeset-bot[bot]

Thanks for the PR. Our current plan is to expose this sort of configuration within the routes themselves — #8383 — so we don't want to add adapter-level configuration for this stuff in the meantime (though there probably will be some default config for +server.js files).

Until we implement that — hopefully soon — you can achieve the same outcome by modifying the contents of .vercel/output. Slightly hacky, but totally within the scope of what the Build Output API is designed to facilitate!

Rich-Harris avatar Jan 19 '23 16:01 Rich-Harris

That would be awesome @Rich-Harris! I'm currently maintaining a custom vercel adapter that fits my needs: I have taken the much simpler route of defining each route config in svelte.config.js in a vercel.json fashion:

const config = {
  kit: {
    adapter: vercel({
      default: {
        runtime: 'node',
        regions: ['fra1'],
        memory: 2048,
        maxDuration: 30
      },
      functions: {
        '/(landing)/.*': {
          runtime: 'edge',
          regions: ['cdg', 'fra']
        },
        '/api/.*': {
          runtime: 'node', // not necessary 
          memory: 1024,
          maxDuration: 45,
        },
        '/api/images/process': {
          memory: 3008,
          maxDuration: 60,
        },
        '/(app)/.*': {
          maxDuration: 10,
        }
      }
    })
  }
};

A bit less hacky than modifying the contents of .vercel/output before each deployment 🙂

Smirow avatar Jan 19 '23 16:01 Smirow