Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for ServerlessFunctionConfig and EdgeFunctionConfig #8458

Closed
wants to merge 5 commits into from

Conversation

Smirow
Copy link

@Smirow Smirow commented Jan 11, 2023

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
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • 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

@changeset-bot
Copy link

changeset-bot bot commented Jan 11, 2023

🦋 Changeset detected

Latest commit: 0884253

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

@benmccann benmccann changed the title Adding support for ServerlessFunctionConfig and EdgeFunctionConfig for adapter-vercel feat: support for ServerlessFunctionConfig and EdgeFunctionConfig Jan 11, 2023
@Rich-Harris
Copy link
Member

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!

@Smirow
Copy link
Author

Smirow commented Jan 19, 2023

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 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:adapter-vercel Pertaining to the Vercel adapter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants