@serverless-normalize/normalize v0.0.11
serverless-normalize đ
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
- AWS (via
@serverless-normalize/aws
) - serverless-offline
- GCP
- ... accepting PRs for other 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
- Alagarr
- serverless-http
- Middy
- corgi
- node-lambda-req
- apigateway-utils
- serverless-utils
- @graphcool/lambda-helpers
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.