UNPKG

@h4ad/serverless-adapter

Version:

Run REST APIs and other web applications using your existing Node.js application framework (NestJS, Express, Koa, Hapi, Fastify and many others), on top of AWS, Azure, Digital Ocean and many other clouds.

127 lines (122 loc) 3.63 kB
import { S as SingleValueHeaders } from '../../headers-DjfGHDmI.js'; import { A as AdapterContract, a as AdapterRequest, G as GetResponseAdapterProps, O as OnErrorProps } from '../../adapter.contract-FnS-TPRj.js'; import 'http'; import 'node:http'; import '../../logger-F8qccesk.js'; /** * The interface to represents the values of args send when someone calls a function using HTTP Endpoint. * To be able to receive this event, inside your `project.yml`, instead of `web: true` change to `web: 'raw'`. * * {@link https://www.digitalocean.com/community/questions/digitalocean-functions-how-to-differentiate-query-params-from-body-params | Reference} * * @public * @breadcrumb Types / Digital Ocean / DigitalOceanHttpEvent */ interface DigitalOceanHttpEvent { /** * The HTTP Method of the request */ __ow_method: string; /** * The query porams of the request */ __ow_query: string; /** * The body of the request. */ __ow_body?: string; /** * Indicates if body is base64 string */ __ow_isBase64Encoded?: boolean; /** * The HTTP Headers of the request */ __ow_headers: SingleValueHeaders; /** * The path in the request */ __ow_path: string; } /** * The interface to represents the response of Digital Ocean Function. * * @public * @breadcrumb Types / Digital Ocean / DigitalOceanHttpResponse */ interface DigitalOceanHttpResponse { /** * The HTTP Headers of the response */ headers?: SingleValueHeaders; /** * The body of the response */ body: unknown; /** * The HTTP Status code of the response */ statusCode: number; } /** * The options to customize the {@link HttpFunctionAdapter} * * @breadcrumb Adapters / Digital Ocean / HttpFunctionAdapter * @public */ interface HttpFunctionAdapterOptions { /** * Strip base path for custom domains * * @defaultValue '' */ stripBasePath?: string; } /** * The adapter to handle requests from Digital Ocean Functions when called from HTTP Endpoint. * * @example * ```typescript * const stripBasePath = '/any/custom/base/path'; // default '' * const adapter = new HttpFunctionAdapter({ stripBasePath }); * ``` * * @breadcrumb Adapters / Digital Ocean / HttpFunctionAdapter * @public */ declare class HttpFunctionAdapter implements AdapterContract<DigitalOceanHttpEvent, void, DigitalOceanHttpResponse> { protected readonly options?: HttpFunctionAdapterOptions | undefined; /** * Default constructor * * @param options - The options to customize the {@link HttpFunctionAdapter} */ constructor(options?: HttpFunctionAdapterOptions | undefined); /** * {@inheritDoc} */ getAdapterName(): string; /** * {@inheritDoc} */ canHandle(event: unknown): event is DigitalOceanHttpEvent; /** * {@inheritDoc} */ getRequest(event: DigitalOceanHttpEvent): AdapterRequest; /** * {@inheritDoc} */ getResponse({ headers: responseHeaders, body, statusCode, }: GetResponseAdapterProps<DigitalOceanHttpEvent>): DigitalOceanHttpResponse; /** * {@inheritDoc} */ onErrorWhileForwarding({ error, delegatedResolver, respondWithErrors, event, log, }: OnErrorProps<DigitalOceanHttpEvent, DigitalOceanHttpResponse>): void; /** * Get path from event with query strings * * @param event - The event sent by digital ocean */ protected getPathFromEvent(event: DigitalOceanHttpEvent): string; } export { HttpFunctionAdapter, type HttpFunctionAdapterOptions };