Laconia

Laconia

  • Getting Started
  • API
  • Help

›Guides

Introduction

  • Getting Started
  • Motivation
  • Core Concepts
  • Philosophy
  • Examples
  • FAQ
  • Support Me

Laconia vs. Other

  • Claudia
  • Express, Koa, Hapi, etc.
  • Middy
  • Serverless, SAM, Apex, etc.

Guides

  • Injecting Dependencies
  • Unit Testing
  • Adapting Events
  • Creating API Endpoints
  • Retrieving Secrets
  • Retrieving Config
  • Warming Up
  • Invoking Other Lambdas
  • Long Running Tasks
  • Creating Middleware

API Reference

  • API Reference: Intro
  • core
  • event
  • adapter
  • adapter-api
  • invoker
  • config
  • batch
  • middleware-lambda-warmer
  • middleware-serverless-plugin-warmup
Edit

Creating Middleware

Overview

As per Laconia's philosophy, Laconia doesn't support middleware as a framework and have its middleware concept a simple decorator function instead, hence it is not actually dependent on Laconia at all. Laconia recommends the use of middleware on your Handler i.e. before the adapter. Middlewares in Laconia should only deal with Cloud provider specific concerns that are not part of your adapter's responsibility.

Creating a middleware

Let's go and try to create a simple middleware for a handler. In the example below, all the requests coming in to your Lambda will be logged.

const laconia = require("@laconia/core");

// Define a new middleware
const myMiddleware = next => (event, context, callback) => {
  console.log("Logging all events in my middleware", event);
  return next(event, context, callback);
};

const app = (event, laconiaContext) => {};
const handler = laconia(app);

exports.handler = myMiddleware(handler); // Wrap your handler with a middleware
← Long Running TasksAPI Reference: Intro →
  • Overview
  • Creating a middleware
Laconia
Docs
Getting StartedCore ConceptsAPI Reference
Community
Stack OverflowChat
More
TwitterGitHubStar
Copyright © 2022 Wisen Tanasa
Logo designed by Suzie Nam