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.
npm install @mionjs/platform-vercel @mionjs/router
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();
import {Routes, route} from '@mionjs/router';
export const routes = {
sayHello: route((ctx, name: string): string => {
return `Hello ${name}!`;
}),
} satisfies Routes;
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.
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': '*'},
});
Request -> Response API and works in both Node.js and Edge environments without changes.export interface VercelHandlerOptions {
/** Set of default response headers to add to every response */
defaultResponseHeaders: Record<string, string>;
}