@flexible-agency/serverless-middleware

1.5.1 • Public • Published

Serverless Middleware

Some helpers for writing API endpoints using AWS Lambda and Laconia.


Installation

yarn add @flexible-agency/serverless-middleware

Example usage

import { middleware, auth } from '@flexible-agency/serverless-middleware';

const dependencies = () => ({
	// dependencies for the Laconia dependency injector
});

export const app = async({ query, path, body }, { currentUser, /* dependences */ }) => {
	// if `auth` is included in the second param of `middleware`, currentUser
	// will be an object in the form of `{ id, groups, email, ... }`

	// your business logic goes here

	return {
		success: true,
		text: 'Hello, world!'
	};
}

export const handler = middleware(app, [auth]).register(dependencies);

Options

Warmup support

Out of the box this middleware setup supports the serverless-plugin-warmup serverless plugin.

Simply install the serverless plugin, no other changes to your code necessary. The middleware will automatically prevent code execution on warmup requests.




Get professional support for this package →
Custom consulting sessions availabe for implementation support and feature development.

Package Sidebar

Install

npm i @flexible-agency/serverless-middleware

Weekly Downloads

29

Version

1.5.1

License

MIT

Unpacked Size

9.09 kB

Total Files

6

Last publish

Collaborators

  • tschoffelen