Run mion in Google Cloud
Google Cloud HTTP Handler for mion APIs! It is just an small wrapper around the mion router.
npm install
npm i @mionkit/gcloud
Export a Google Cloud Http Function
init GC Function
import {GoogleCFOptions, googleCFHandler, setGoogleCFOpts} from '@mionkit/gcloud';
import './myApi.routes';
// set options specific for GC Cloud Functions
const gcfOptions: Partial<GoogleCFOptions> = {};
setGoogleCFOpts(gcfOptions);
// export Google Cloud Functions Handler
export const handler = googleCFHandler;
Quick Tip:
It is a good idea to split the routes definition and server initialization code so mion can be easily configured to run on multiple environments!
It is a good idea to split the routes definition and server initialization code so mion can be easily configured to run on multiple environments!
Type Reference
RouterOptions
Basic options to configure mion router. These options are independent of the environment mion is being used (server or serverless).
export interface RouterOptions<Req = any, SharedData = any> extends CoreOptions {
/** prefix for all routes, i.e: api/v1.
* path separator is added between the prefix and the route */
prefix: string;
/** suffix for all routes, i.e: .json.
* Not path separators is added between the route and the suffix */
suffix: string;
/** Transform the path before finding a route */
pathTransform?: (request: Req, path: string) => string;
/** factory function to initialize shared call context data */
sharedDataFactory?: SharedDataFactory<SharedData>;
/** enable automatic parameter validation, defaults to true */
useValidation: boolean;
/** Enables serialization/deserialization */
useSerialization: boolean;
/** Reflection and Deepkit Serialization-Validation options */
reflectionOptions: ReflectionOptions;
/** Custom JSON parser, defaults to Native js JSON */
bodyParser: JsonParser;
/** Used to return public data structure when adding routes */
getPublicRoutesData: boolean;
/** automatically generate and uuid */
autoGenerateErrorId: boolean;
/** client routes are initialized by default */
skipClientRoutes: boolean;
}
GoogleCFOptions
Most of the options to configure the handler must be set in google cloud.
export interface GoogleCFOptions {
/** Set of default response header to add to every response*/
defaultResponseHeaders: Record<string, string>;
}
Table of Contents