Giter VIP home page Giter VIP logo

middleware's Introduction

L³ middleware

Collection of plugins for use in your application.

Supported plugins

Name Description
AccessControlHeaders Middleware to send Access-Control-* headers.
AppConfigPlugin Middleware to store the app configuration.
BasicAuthHandler Middleware to prompt Basic Authentication.
CloudFrontCacheHeader Middleware to send CloudFront Cache-Control header.
CookieParserPlugin Middleware to parse/store incoming HTTP cookies.
ContentNegotiationJson Middleware to enforce JSON content negotiation.
ContentTypeJsonHeader Middleware to send JSON Content-Type header.
GoogleRecaptchaHandler Middleware to validate Google ReCAPTCHA invisible responses.
PreflightOptionsHandler Middleware to handle preflight requests.
SessionPluginExample Middleware example of validating a session that uses cookies.
SwaggerUIViewer Middleware 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';

const Router = require('@lambda-lambda-lambda/router');

// Load middleware.
const plugin1 = require(`${APP_ROOT}/middleware/PluginName1`);
const plugin2 = require(`${APP_ROOT}/middleware/PluginName2`);
const plugin3 = require(`${APP_ROOT}/middleware/PluginName3`);

/**
 * @see AWS::Serverless::Function
 */
exports.handler = (event, context, callback) => {
  const {request, response} = event.Records[0].cf;

  const router = new Router(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.
const plugin1 = require(`${APP_ROOT}/middleware/PluginName1`);
const plugin2 = require(`${APP_ROOT}/middleware/PluginName2`);
const plugin3 = require(`${APP_ROOT}/middleware/PluginName3`);

/**
 * @export {Object}
 */
module.exports = {

  // Executed in order (route only) /api/foo
  middleware: [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

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.