Platforms

Vercel

Running mion APIs as Vercel Functions.

@mionjs/platform-vercel runs mion as a Vercel Function: re-export its GET, POST, PUT, DELETE, PATCH and OPTIONS handlers from one function file. OPTIONS lets a CORS preflight reach mion.

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, OPTIONS} = createVercelHandler();

One Function for Every Path

A file under api/ serves only its own path. Add a rewrite that sends every path under /api/ to your function. The function still sees the requested path, which mion routes.

vercel.json
{
  "rewrites": [{"source": "/api/(.*)", "destination": "/api/mion"}]
}

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, OPTIONS} = 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