Platforms
Google Cloud Functions
Running mion APIs on Google Cloud Functions for serverless deployments.
@mionjs/platform-gcloud provides a handler for Cloud Functions events.
Installing the Adapter
npm install @mionjs/platform-gcloud @mionjs/router
Creating the Handler
import {createGoogleCFHandler} from '@mionjs/platform-gcloud';
import './gcloud-routes.ts';
export const api = createGoogleCFHandler();
import {createMionRouter, Routes} from '@mionjs/router';
const mion = createMionRouter();
const routes = {
sayHello: mion.route((ctx, name: string): string => {
return `Hello ${name}!`;
}),
} satisfies Routes;
// the server entry only imports this file
export const myApi = mion.initRoutes(routes);
export type MyApi = typeof myApi;
Deployment
Deploy with the gcloud CLI:
gcloud functions deploy api \
--runtime nodejs22 \
--trigger-http \
--allow-unauthenticated
Adapter Options
Pass options such as maxBodySize (128 KB by default) and maxBodySizeCap to createGoogleCFHandler. maxBodySizeCap defaults to the 10 MB Google allows on a 1st gen function; override it on 2nd gen (32 MB). Set router options like basePath once in createMionRouter, and see Request Size for body limits.
import {createGoogleCFHandler} from '@mionjs/platform-gcloud';
import './gcloud-routes.ts';
export const api = createGoogleCFHandler({});
For faster cold starts, keep dependencies minimal. Consider Cloud Run for more control over the runtime.