mion can run on Google Cloud Functions for serverless deployments. The @mionkit/gcloud package provides a handler compatible with Cloud Functions events.
npm install @mionkit/gcloud @mionkit/router
import {initMionGcloud} from '@mionkit/gcloud';
import {routes} from './gcloud-routes.ts';
export const api = initMionGcloud(routes);
import {Routes, route} from '@mionkit/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 {initMionGcloud} from '@mionkit/gcloud';
import {routes} from './gcloud-routes.ts';
export const api = initMionGcloud(routes, {
prefix: '/api', // API prefix
// ... other router options
});
export interface GoogleCFOptions {
/** Set of default response header to add to every response*/
defaultResponseHeaders: Record<string, string>;
}