Platforms

Vercel

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

@mionjs/platform-vercel runs mion as Next.js App Router route handlers. It returns GET, POST, PUT, DELETE and PATCH handlers that you re-export from a catch-all route file.

Installing the Adapter

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

Creating the Handler

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

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

Catch-all Route

One route file handles every method. Place it in a Next.js App Router catch-all directory, whose [...mion] segment sends every path under /api/ to mion's router.

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

The same handler also hosts your API inside a Next app, see Hosting the API in Your Next App.

API Base Path

Set basePath: '/api' on the router and the client, and point the client's baseURL at the origin. Putting /api in baseURL does not work: a route path is absolute, so it replaces the base's path and drops the prefix.

// your routes module
const mion = createMionRouter({basePath: '/api'});

// your client
const {routes} = initClient<MyApi>({baseURL: 'https://your-app.vercel.app', basePath: '/api'});

Handler Options

Pass options such as maxBodySize (128 KB by default) and maxBodySizeCap to createVercelHandler. maxBodySizeCap defaults to the 4.5 MB Vercel allows, and Vercel refuses anything bigger before the function runs; override it if Vercel changes it. Each route has its own body limit, and a body stream past it is cancelled with a 413.

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

export const {GET, POST, PUT, DELETE, PATCH} = createVercelHandler({
  maxBodySize: 512 * 1024,
});
The handler uses the Web standard Request -> Response API, so it runs on both the Node.js and Edge runtimes without changes.
The Edge runtime forbids new Function() and eval(), so an Edge build must set runTypes: {emitMode: 'both'} on the mion Vite plugin:
vite.config.ts
mionVitePlugin({
    runTypes: {
        // required on Edge: no `new Function` at runtime
        emitMode: 'both',
    },
}),
Otherwise mion.initRoutes fails with "Code generation from strings disallowed for this context". See Cloudflare Workers for why, and the bundle-size cost. Node.js-runtime deployments need no such change.
Copyright © 2026