Platforms

Vercel

Running mion APIs on Vercel using Next.js App Router route handlers.

mion can run on Vercel as a set of Next.js App Router route handlers. The @mionjs/platform-vercel package returns an object with GET, POST, PUT, DELETE, and PATCH exports that you re-export from a catch-all route file.

Installation

npm install @mionjs/platform-vercel @mionjs/router

Quick Start

import {createVercelHandler} from '@mionjs/platform-vercel';
import {initMionRouter} from '@mionjs/router';
import {routes} from './vercel-routes.ts';

await initMionRouter(routes);

export const {GET, POST, PUT, DELETE, PATCH} = createVercelHandler();

Catch-all Route

mion uses a single route file that handles every method. Place your handler in a Next.js App Router catch-all directory:

app/
  api/
    [...mion]/
      route.ts   ← exports GET/POST/PUT/DELETE/PATCH from createVercelHandler()

The [...mion] segment captures every path under /api/, allowing mion's router to dispatch requests to the correct route handler regardless of the URL. Make sure your client baseUrl points to /api.

Configuration

You can pass configuration options to createVercelHandler:

import {createVercelHandler} from '@mionjs/platform-vercel';
import {initMionRouter} from '@mionjs/router';
import {routes} from './vercel-routes.ts';

await initMionRouter(routes, {
    basePath: 'api',
});

export const {GET, POST, PUT, DELETE, PATCH} = createVercelHandler({
    defaultResponseHeaders: {'access-control-allow-origin': '*'},
});
Vercel also supports running mion on the Edge runtime. The handler is built on the Web standard Request -> Response API and works in both Node.js and Edge environments without changes.

Type Reference

VercelHandlerOptions

export interface VercelHandlerOptions {
    /** Set of default response headers to add to every response */
    defaultResponseHeaders: Record<string, string>;
}