1.2 KiB
1.2 KiB
Astro Integration - SKILLS.md
What It Is
Run Elysia on Astro via Astro Endpoint.
Setup
- Set output to server:
// astro.config.mjs
export default defineConfig({
output: 'server'
})
- Create
pages/[...slugs].ts - Define Elysia server + export 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
WinterCG compliance - works normally.
Recommended: Run Astro on Bun (Elysia designed for Bun).
Prefix for Non-Root
If placed in pages/api/[...slugs].ts, set prefix:
// pages/api/[...slugs].ts
const app = new Elysia({ prefix: '/api' })
.get('/', () => 'hi')
const handle = ({ request }: { request: Request }) => app.handle(request)
export const GET = handle
export const POST = handle
Ensures routing works in any location.
Benefits
Co-location of frontend + backend. End-to-end type safety with Eden.
pnpm
Manual install:
pnpm add @sinclair/typebox openapi-types