Platforms

Google Cloud Functions

Running mion APIs on Google Cloud Functions for serverless deployments.

mion can run on Google Cloud Functions for serverless deployments. The @mionkit/gcloud package provides a handler compatible with Cloud Functions events.

Installation

npm install @mionkit/gcloud @mionkit/router

Quick Start

import {initMionGcloud} from '@mionkit/gcloud';
import {routes} from './gcloud-routes.ts';

export const api = initMionGcloud(routes);

Deployment

Deploy your function using the gcloud CLI:

gcloud functions deploy api \
  --runtime nodejs18 \
  --trigger-http \
  --allow-unauthenticated

Configuration

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
});
For optimal cold start performance, keep your function dependencies minimal and consider using Cloud Run for more control over the runtime environment.

Type Reference

GoogleCFOptions

export interface GoogleCFOptions {
    /** Set of default response header to add to every response*/
    defaultResponseHeaders: Record<string, string>;
}