JSPM

  • Created
  • Published
  • Downloads 23
  • Score
    100M100P100Q68722F
  • License MIT

Export node.js applications into serverless compatible functions

Package Exports

  • @stormkit/serverless
  • @stormkit/serverless/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@stormkit/serverless) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Stormkit Serverless

Export node.js applications into serverless compatible functions

Why?

Stormkit servesless provides handy wrappers to make your code work in serverless environments. This makes your function much more portable. The wrapper will take the incoming event and transform it into a Node.js http.IncomingMessage object.

Example usage

import http from "http";
import serverless from "@stormkit/serverless";

export const handler = serverless(
  (req: http.IncomingMessage, res: http.ServerResponse) => {
    res.write("Hello from " + req.url);
    res.end();
  }
);

By default the above example will use a Stormkit handler. To change this behaviour you can tell the serverless function which handler to use.

export const handler = serverless(
  (req: http.IncomingMessage, res: http.ServerResponse) => {
    res.write("Hello from " + req.url);
    res.end();
  },
  "awsAlb"
);

In order to avoid setting the handler type all the time, you can also use the process.env.SERVERLESS_HANDLER environment variable to set a different default type. Allowed types are:

  • awsAlb
  • stormkit

If you need a different handler, feel free to open a issue 🙏🏻

Currently supported signatures

Each provider has it's own signature to call a serverless function. Here's the list of the currently supported providers:

License

Made with 💛 Published under MIT.