Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/elysiajs/documentation/llms.txt

Use this file to discover all available pages before exploring further.

With Astro Endpoints, you can run Elysia directly inside your Astro project. Because Elysia is WinterTC-compliant, it handles requests using the same Web Standard Request/Response API that Astro endpoints use.
1

Set output to server in astro.config.mjs

// astro.config.mjs
import { defineConfig } from 'astro/config'

export default defineConfig({
  output: 'server'
})
2

Create a catch-all endpoint file

Create pages/[...slugs].ts in your Astro project.
3

Define your Elysia server and export method handlers

// pages/[...slugs].ts
import { Elysia, t } from 'elysia'

const app = new Elysia()
  .get('/api', () => 'hi')
  .post('/api', ({ body }) => body, {
    body: t.Object({
      name: t.String()
    })
  })

const handle = ({ request }: { request: Request }) => app.handle(request)

export const GET = handle
export const POST = handle
We recommend running Astro on Bun since Elysia is designed to run on Bun. That said, Elysia will work with any Astro adapter thanks to WinterTC support.

Route prefix

If you place your endpoint in a subdirectory (e.g. pages/api/[...slugs].ts), set the prefix option on your Elysia server to match:
// pages/api/[...slugs].ts
import { Elysia, t } from 'elysia'

const app = new Elysia({ prefix: '/api' })
  .get('/', () => 'hi')
  .post('/', ({ body }) => body, {
    body: t.Object({
      name: t.String()
    })
  })

const handle = ({ request }: { request: Request }) => app.handle(request)

export const GET = handle
export const POST = handle

pnpm peer dependencies

If you use pnpm, install peer dependencies manually:
pnpm add @sinclair/typebox openapi-types
See Astro Endpoints for further reference on the Astro endpoint API.

Build docs developers (and LLMs) love