@robojs/server
Turn your Robo into a web server with file-based routing, typed endpoints, and more.
This plugin adds HTTP server capabilities to any Robo project. Create files in /src/api and they become web endpoints automatically. It supports typed endpoints with Zod, static file serving, CORS, tunnels, WebSocket, and multiple server engines.
Installation
Add the plugin to an existing Robo project:
npx robo add @robojs/server@nextOr scaffold a new project with it included:
npx create-robo@next my-project -p @robojs/server@nextQuick example
Create a file in /src/api and export HTTP method handlers:
import type { RoboRequest } from '@robojs/server'
export function GET() {
return { message: 'Hello, world.' }
}
export async function POST(request: RoboRequest) {
const body = await request.json()
return { received: body }
}
export function GET() {
return { message: 'Hello, world.' }
}
export async function POST(request) {
const body = await request.json()
return { received: body }
}Run your Robo and visit http://localhost:3000/api/hello. The GET handler returns a JSON response. Send a POST request to the same URL with a JSON body to see it echoed back.
Features
File-based Routing
Files in /src/api map to URL paths automatically
Typed Endpoints
Zod schemas for TypeScript inference and OpenAPI generation
Static Files
Serve public/ directory with SPA fallback
CORS
Enable cross-origin requests with a single config option
Tunnels
Expose your local server via Cloudflare tunnels
WebSocket
Path-scoped WebSocket handlers with upgrade support
Testing Utils
Unit test API routes without starting a server
Custom Engines
Ships with Node.js and Fastify, or bring your own
Learning path
Start with the quick start to get a server running, then explore routing patterns and typed endpoints for production-grade APIs. The reference section covers all configuration options and the full API.
