Skip to content
Deploy with Vercel

Integration with Vercel Function

Vercel Function support Web Standard Framework by default, so you can run Elysia on Vercel Function without any additional configuration.

  1. Create a file at api/index.ts
  2. In index.ts, create or import an existing Elysia server
  3. Export the Elysia server as default export
typescript
import { Elysia, t } from 'elysia'

export default new Elysia()
    .get('/', () => 'Hello Vercel Function')
    .post('/', ({ body }) => body, {
        body: t.Object({
            name: t.String()
        })
    })
  1. Create vercel.json to rewrite the API route to Elysia server
json
{
    "$schema": "https://openapi.vercel.sh/vercel.json",
    "rewrites": [
		{
			"source": "/(.*)",
			"destination": "/api"
		}
    ]
}

This configuration will rewrite all requests to the /api route, which is where Elysia server is defined.

No additional configuration is needed for Elysia to work with Vercel Function, as it supports the Web Standard Framework by default.

You can also use Elysia's built-in features like validation, error handling, OpenAPI (scalar) and more, just like you would in any other environment.

For additional information, please refer to Vercel Function documentation.