Skip to content

Commit

Permalink
docs: Updates vercel config for functions (#10891)
Browse files Browse the repository at this point in the history
Fixes: #10022 and
#1664

Documents support for Vercel API endpoint (ie, functions) configuration
via `export const config` syntax.

Can deploy docs here vercel/vercel#11776 merges.

---------

Co-authored-by: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com>
  • Loading branch information
dthyresson and Josh-Walker-GM committed Jul 19, 2024
1 parent cd6f24d commit 89c19f6
Showing 1 changed file with 46 additions and 9 deletions.
55 changes: 46 additions & 9 deletions docs/docs/deploy/vercel.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,54 @@ From the Vercel Dashboard you can access the full settings and information for y

From now on, each time you push code to your git repo, Vercel will automatically trigger a deploy of the new code. You can also manually redeploy if you select "Deployments", then the specific deployment from the list, and finally the "Redeploy" option from the vertical dots menu next to "Visit".

## vercel.json configuration
## Configuration

By default, API requests in Vercel have a timeout limit of 15 seconds. To extend this duration, you can modify the vercel.json file by inserting the code snippet provided below. Please be aware that the ability to increase the timeout limit is exclusive to Pro plan subscribers. Additionally, it is important to note that the timeout can be increased up to a maximum of 300 seconds, which is equivalent to 5 minutes.
You can use `vercel.json` to configure and override the default behavior of Vercel from within your project. For [`functions`](#functions), you should configure in code directly and not in `vercel.json`.

```
{
"functions": {
"api/src/functions/graphql.*": {
"maxDuration": 120,
"runtime": "@vercel/redwood@2.0.5"
}
### Project

The [`vercel.json` configuration file](https://vercel.com/docs/projects/project-configuration#configuring-projects-with-vercel.json) lets you configure, and override the default behavior of Vercel from within your project such as rewrites or headers.

### Functions

By default, API requests in Vercel have a timeout limit of 15 seconds, but can be configured to be up to 90 seconds. Pro and other plans allow for longer [duration](https://vercel.com/docs/functions/runtimes#max-duration) and larger [memory-size limits](https://vercel.com/docs/functions/runtimes#memory-size-limits).

To change the `maxDuration` or `memory` per function, export a `config` with the settings you want applied in your function. For example:

```ts
import type { APIGatewayEvent, Context } from 'aws-lambda'

import { logger } from 'src/lib/logger'

export const config = {
maxDuration: 30,
memory: 512,
}

export const handler = async (event: APIGatewayEvent, _context: Context) => {
logger.info(`${event.httpMethod} ${event.path}: vercel function`)

return {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
data: 'vercel function',
}),
}
}

```

:::tip important
Since Redwood has it's own handling of the api directory, the Vercel flavored api directory is disabled. Therefore you don't use the "functions" config in `vercel.json` with Redwood.

Also, be sure to use Node version 20.x or greater or set the `runtime` in the function config:
```ts
export const config = {
runtime: 'nodejs20.x',
}
```

:::

0 comments on commit 89c19f6

Please sign in to comment.