Skip to content

๐ŸŽ Normalize your serverless functions! ๐ŸŽ‰

License

Notifications You must be signed in to change notification settings

Zn4rK/serverless-normalize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

27 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

serverless-normalize ๐Ÿ˜Ž

Test status Coverage Status

Normalize your serverless functions by abstracting away the differences between the different serverless providers. It adds a standardized request/response model, that you can hook into any framework you like - or use it as is!

The package @serverless-normalize/normalize automatically identifies which provider you are using and if you have the compatibility layer installed for that provider, it'll call your function with the Node.js standard HTTP request and response objects.

Support

Supported Providers

Installation

npm install @serverless-normalize/normalize --save

If you are using AWS or serverless-offline you'll also need the compatibility layer.

npm install @serverless-normalize/aws --save

API

normalize(callback: Function, options?: object): any

The callback has a function signature of:

type Callback = (
  request: http.IncomingMessage,
  response: http.ServerResponse,
) => void

options is optional and depends on the provider. Sensible defaults are used for all the providers.

Examples

With Koa:

// handler.js
import { normalize } from '@serverless-normalize/normalize';
import Koa from 'koa';

const app = new Koa();

app.use(async ctx => {
  ctx.status = 200;
  ctx.body = JSON.stringify({ message: 'Yay!' });
});

export default normalize(app.callback());

FAQ

  • Why the relative require?

    Two reasons:
    There is no support for "optionalPeerDependencies" in a package.json file - and we don't want to load more code than necessary.

    And the other reason is because of module bundlers (like Webpack) to still be able to do their analysis and not emit errors or warnings about missing packages (which they would have been if you only include the providers you plan on using).

    Since scoped packages installs every package under your own scope, this works!

Similar Projects

Contributing

Contributions are more than welcome! Just fork and clone the repository and run npm install.

License

serverless-normalize ยฉ Alexander Liljengรฅrd. Released under the MIT license.
Authored and maintained by Alexander Liljengรฅrd with help from contributors.

About

๐ŸŽ Normalize your serverless functions! ๐ŸŽ‰

Resources

License

Stars

Watchers

Forks

Packages