2.3.4 • Published 20 days ago

@stormkit/serverless v2.3.4

Weekly downloads
-
License
MIT
Repository
github
Last release
20 days ago

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.

For whom is this package targeted for?

This repository is intended for users who care about portability. If you know you'll be using AWS Lambda and you don't need to make your code portable, then this package may be overengineering for your needs. If, however, you'd like to deploy your application to multiple providers, then this package can be helpful.

If you are using Stormkit and developing an API, you can use this repository to test your application locally.

Installation

npm i @stormkit/serverless

Example usage

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

export const handler = serverless(
  async (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(
  async (req: http.IncomingMessage, res: http.ServerResponse) => {
    res.write("Hello from " + req.url);
    res.end();
  },
  "awsAlb"
);

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:

Dev Server

To test your serverless application locally, execute the following command:

node ./node_modules/@stormkit/serverless/dev-server

This will spin up a local dev server and start serving requests from your /api folder. The Dev Server uses a filesystem routing mechanism, therefore each request will be forwarded to the relevant file. For example:

/user/subscriptions will be routed to $REPO/api/user/subscriptions.ts or $REPO/api/user/subscriptions.js where $REPO is path to your repository. For dynamic paths, you can prefix your subfolders with a double-colon :. For instance, if your folder structure is $REPO/api/user/:id/subscriptions.ts, a request with path /user/15/subscriptions will be matched and served from that file.

If you see a SyntaxError: unexpected token 'export' error try adding the following configuration to the tsconfig.json file:

{
  "compilerOptions": {
    "module": "commonjs"
  }
}

Testing this repo locally

To run an e2e test locally, use the tests/e2e/run.ts file:

ts-node tests/e2e/run.ts --repo <path-to-repo> --dist-dir <path-to-dist>
argumentdescription
repoRequired. Absolute path to the repository to test against.
dist-dirOptional. If the tested repository is not a framework, provide the dist dir.

Make sure that the repo that is tested is built.

License

Made with 💛 Published under MIT.

2.3.0

20 days ago

2.3.2

20 days ago

2.3.1

20 days ago

2.3.4

20 days ago

2.3.3

20 days ago

2.2.3

2 months ago

2.2.4

2 months ago

2.2.2

2 months ago

2.2.1

3 months ago

2.2.0

3 months ago

2.1.4

5 months ago

2.1.3

5 months ago

1.2.0

8 months ago

1.2.4

7 months ago

1.2.3

7 months ago

1.2.2

7 months ago

1.2.1

7 months ago

2.0.3

7 months ago

2.0.2

7 months ago

2.0.5

7 months ago

2.0.4

7 months ago

2.0.7

7 months ago

2.0.6

7 months ago

2.0.9

5 months ago

2.0.8

7 months ago

2.0.1

7 months ago

2.0.0

7 months ago

2.0.0-0

7 months ago

2.1.2

5 months ago

2.1.1

5 months ago

2.1.0

5 months ago

1.1.4

11 months ago

1.0.5

1 year ago

1.0.4

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.0.3

1 year ago

0.17.2

1 year ago

0.17.3

1 year ago

0.17.4

1 year ago

0.17.0

1 year ago

0.17.1

1 year ago

0.16.1

1 year ago

0.16.2

1 year ago

0.9.12

2 years ago

0.9.13

2 years ago

0.9.14

2 years ago

0.9.10

2 years ago

0.9.11

2 years ago

0.11.0

2 years ago

0.15.0

1 year ago

0.9.9

2 years ago

0.12.7

2 years ago

0.12.8

2 years ago

0.12.0

2 years ago

0.12.1

2 years ago

0.14.0

1 year ago

0.14.1

1 year ago

0.16.0

1 year ago

0.14.2

1 year ago

0.12.5

2 years ago

0.12.6

2 years ago

0.10.0

2 years ago

0.9.8

2 years ago

0.9.7

2 years ago

0.9.4

2 years ago

0.9.6

2 years ago

0.9.5

2 years ago

0.9.3

2 years ago

0.9.0

2 years ago

0.8.1

2 years ago

0.8.0

2 years ago

0.9.2

2 years ago

0.9.1

2 years ago

0.8.2

2 years ago

0.7.6

2 years ago

0.7.5

2 years ago

0.7.8

2 years ago

0.7.7

2 years ago

0.7.2

2 years ago

0.6.3

2 years ago

0.5.4

2 years ago

0.4.5

2 years ago

0.7.1

2 years ago

0.6.2

2 years ago

0.5.3

2 years ago

0.4.4

2 years ago

0.7.4

2 years ago

0.7.3

2 years ago

0.6.4

2 years ago

0.5.0

2 years ago

0.7.0

2 years ago

0.6.1

2 years ago

0.5.2

2 years ago

0.4.3

2 years ago

0.6.0

2 years ago

0.5.1

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago