Skip to content

Repository files navigation

L³ middleware

Build StatusNO AI

Collection of plugins for use in your application.

Supported plugins

NameDescription
AccessControlHeadersMiddleware to send Access-Control-* headers.
AppConfigPluginMiddleware to support a file-based app configuration.
BasicAuthHandlerMiddleware to prompt Basic Authentication.
CloudFrontCacheHeaderMiddleware to send CloudFront Cache-Control header.
CookieParserPluginMiddleware to parse/store incoming HTTP cookies.
ContentNegotiationJsonMiddleware to enforce JSON content negotiation.
ContentTypeJsonHeaderMiddleware to send JSON Content-Type header.
GoogleRecaptchaHandlerMiddleware to validate Google ReCAPTCHA invisible responses.
PreflightOptionsHandlerMiddleware to handle preflight requests.
SecretsManagerPluginMiddleware to support AWS Secrets Manager based app configuration.
SessionPluginExampleMiddleware example of validating a session that uses cookies.
SwaggerUIViewerMiddleware to generate Swagger UI viewer.

Installation

Install using the L³ CLI

Usage: lambda-lambda-lambda install [options] <PackageName>
Arguments:
PackageName Package name (Example: BasicAuthHandler)
Options:
-h, --help display help for command

Manual installation

Copy the package to your application /middleware and include accordingly.

Usage

Globally scoped

// .. appName/src/app.js'use strict';constRouter=require('@lambda-lambda-lambda/router');// Load middleware.constplugin1=require(`${APP_ROOT}/middleware/PluginName1`);constplugin2=require(`${APP_ROOT}/middleware/PluginName2`);constplugin3=require(`${APP_ROOT}/middleware/PluginName3`);/** * @see AWS::Serverless::Function */exports.handler=(event,context,callback)=>{const{request, response}=event.Records[0].cf;constrouter=newRouter(request,response);// Executed in order (all routes) /api/*router.use(plugin1);router.use(plugin2);router.use(plugin3);// .. Router Methods};

Locally scoped

// .. appName/src/routes/foo.js'use strict';// Load middleware.constplugin1=require(`${APP_ROOT}/middleware/PluginName1`);constplugin2=require(`${APP_ROOT}/middleware/PluginName2`);constplugin3=require(`${APP_ROOT}/middleware/PluginName3`);/** * @export {Object} */module.exports={// Executed in order (route only) /api/foomiddleware: [plugin1,plugin2,plugin3],// .. Router Methods};

Developers

CLI options

From the plugin directory:

$ cd plugins/<pluginName>

Run ESLint on project sources:

$ npm run lint

Run Mocha integration tests:

$ npm run test

AWS changes starting in Node.js 24 (CloudWatch warning)

Going forward, it is recommended that you build your L³ application using async handlers in anticipation of the AWS changes below.

AWS Lambda plans to remove support for callback-based function handlers starting with Node.js 24. You will need to update this function to use an async handler to use Node.js 24 or later. For more information and to provide feedback on this change, see aws/aws-lambda-nodejs-runtime-interface-client#137

While backwards compatibity will be supported for older Node.js releases this support will eventually be phased out with the deprecation of nodejs22.x (Apr 30, 2027).

See AWS Node.js Supported Runtimes for support information.

Contributions

If you fix a bug, or have a code you want to contribute, please send a pull-request with your changes. (Note: Before committing your code please ensure that you are following the Node.js style guide)

Versioning

This package is maintained under the Semantic Versioning guidelines.

License and Warranty

This package is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.

lambda-lambda-lambda/middleware is provided under the terms of the MIT license

Author

Marc S. Brooks

About

💼 Collection of plugins for use in your L³ application.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages