mion can run on Google Cloud Functions for serverless deployments. The @mionjs/platform-gcloud package provides a handler compatible with Cloud Functions events.
npm install @mionjs/platform-gcloud @mionjs/router
import {createGoogleCFHandler} from '@mionjs/platform-gcloud';
import {initMionRouter} from '@mionjs/router';
import {routes} from './gcloud-routes.ts';
await initMionRouter(routes);
export const api = createGoogleCFHandler();
import {Routes, route} from '@mionjs/router';
export const routes = {
sayHello: route((ctx, name: string): string => {
return `Hello ${name}!`;
}),
} satisfies Routes;
Deploy your function using the gcloud CLI:
gcloud functions deploy api \
--runtime nodejs18 \
--trigger-http \
--allow-unauthenticated
You can pass configuration options to initMionGcloud:
import {createGoogleCFHandler} from '@mionjs/platform-gcloud';
import {initMionRouter} from '@mionjs/router';
import {routes} from './gcloud-routes.ts';
await initMionRouter(routes, {
basePath: 'api', // API prefix
});
export const api = createGoogleCFHandler({});
export interface GoogleCFOptions {
/** Set of default response header to add to every response*/
defaultResponseHeaders: Record<string, string>;
}