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 @mionjs/platform-gcloud package provides a handler compatible with Cloud Functions events.

Installation

npm install @mionjs/platform-gcloud @mionjs/router

Quick Start

import {createGoogleCFHandler} from '@mionjs/platform-gcloud';
import {initMionRouter} from '@mionjs/router';
import {routes} from './gcloud-routes.ts';

await initMionRouter(routes);

export const api = createGoogleCFHandler();

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 {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({});
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>;
}