npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

legerdemain

v0.1.1

Published

Let's your express app understand the AWS API Gateway event/context functions.

Downloads

7

Readme

Legerdemain

Lets your Node.js Express app understand Amazon's API Gateway/Lambda requests.

Status

Legerdemain is very much a work in progress. Don't use it for production. Please do report problems & use cases in the Issues tab on Github.

Legerdemain is part of Hocus Pocus, and works well with Hocus and Pocus. You can use Legerdemain without Hocus and Pocus, but you'll have to do a lot more things manually.

Installation

  1. Install Legerdemain from NPM.
npm install legerdemain --save
  1. Make sure your main application file (something like app.js) has module.exports line. This is created by default by Express:
module.exports = app;
  1. Create a file to expose a Lambda handler, with this as it's contents. We'll refer to this file as translator.js in the next step.
var legerdemain = require('legerdemain');
var app = require('./app.js');
exports.handlers = legerdemain.bind(app)

Upload as an AWS Lambda

  1. Zip up the contents of your app. Do not zip up the folder, just the contents.

  2. Create a new Lambda function.

  3. Set the handler to translator.handler.

Setup your API Gateway

  1. Create a new API.

  2. Define your resources and methods to match your app's routes. Map each method to your Lambda.

  3. For each Method in the Gateway:

For the Integration Request, create a Mapping Template with Content-type of application/json. The actual template should look like this:

{
    "stage": "$context.stage",
    "request-id": "$context.requestId",
    "api-id": "$context.apiId",
    "resource-path": "$context.resourcePath",
    "resource-id": "$context.resourceId",
    "http-method": "$context.httpMethod",
    "source-ip": "$context.identity.sourceIp",
    "user-agent": "$context.identity.userAgent",
    "account-id": "$context.identity.accountId",
    "api-key": "$context.identity.apiKey",
    "caller": "$context.identity.caller",
    "user": "$context.identity.user",
    "user-arn": "$context.identity.userArn",
    "queryString": "$input.params().querystring",
    "headers": "$input.params().header",
    "pathParams": "$input.params().path",
    "allParams": "$input.params()"
}

If the method is meant to return HTML,

3a) Create a Method Response with Content-type of text/html and use the Empty Model.

3b) Create an Integration Response with a Mapping Template, Content-type of text/html, with the following actual template:

#set($inputRoot = $input.path('$'))
$inputRoot.data
  1. Deploy your API.

AWS API Gateway will give you the base URL to your app. Open that base url, plus your route, in your browser. For instance, if you have a "/" route, you can just open the base URL that AWS API Gatway provided.

License

MIT