Code Monkey home page Code Monkey logo

lambda-express's People

Contributors

jimjenkins5 avatar jthomerson avatar lukelafountaine avatar onebytegone avatar pbredenberg avatar yokuze avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

lambda-express's Issues

Explore Express 5.0 Featureset

We should see what features Express is shipping in 5.x and see if we need to / should support any of them, and what, if any, of the changes in 5.x are incompatible with the interfaces of Express that we've implemented.

Reference: expressjs/express#2237

Builds are failing on master on latest node

Builds that previously passed (master branch) are now failing on the latest node version. We need to see if this is a problem with the tests, or an actual break in the code, and fix.

JSONP callback param is not sanitized

The current implementation for building a JSONP callback function uses the exact string which was passed to the API. This can create invalid JS if the API was requested with something like: https://example.com/endpoint?callback=%20not%20valid.

Looking at the implementation in express, all but \[\][a-zA-Z0-9_] will be filtered from the callback name. Should lambda-express be doing something similar?

For posterity, other express items that might be of use:

Consider supporting Lambda payload version 2.0

With the introduction of APIGW HTTP APIs, a new version of the payload format between APIGW and Lambda was also introduced - version 2.0 [1]. The serverless framework by default uses version 1.0 when an HTTP API is created. This preserves backward compatibility if switching over from using a REST API. The new format has changes to multi-value headers, the request context object and some others noted here [2]. We might want to consider supporting payload version 2.0. At this point, the need is not urgent as we can continue using v1.0 even with HTTP APIs.

[1] https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
[2] https://medium.com/@lancers/amazon-api-gateway-explaining-lambda-payload-version-2-0-in-http-api-24b0b4db5d36

Add parsing of Accept header to Request

The Request class in express has an accepts function for determining the preferred content type. This functionality along these lines is needed to address this TODO.

This issue is to track the planning and addition of Accept header parsing to the Request class.

Write usage documentation

Need to write usage documentation in the README. It should include:

  • any differences from the API of Express (notably, mounting sub-routers)
  • examples of middleware, request handlers, error handlers
  • hello world

Consider `router.route` method

See

// TODO: do we need `router.route`?
// https://expressjs.com/en/guide/routing.html#app-route
// https://expressjs.com/en/4x/api.html#router.route
// If we do add it, we need to set the case-sensitivity of the sub-router it creates
// using the case-sensitivity setting of this router.

Support internal request re-routing

Express supports internal request re-routing by allowing route handlers to change the request's url property. Lambda-express should support the same to maintain compatibility.

* TODO: We still don't support internal re-routing mid-request. We need to investigate
* how, exactly, Express does this, and what it would take to support it.

"trust proxy" does not make Request.hostname use the value of X-Forwarded-Host

Regarding Request.hostname, the lambda-express code states:

When the trust proxy app setting is truthy, [the hostname] property will instead have the value of the X-Forwarded-Host header field.

Unfortunately, the hostname code doesn't seem to actually do that. Tests that are listed below fail due to this. Seems like either the docs or the code needs to change.

Unit Tests

describe('hostname property', () => {

   const testCases = [
      {
         host: 'b5gee6dacf.execute-api.us-east-1.amazonaws.com',
         expectedWithTrustProxy: 'b5gee6dacf.execute-api.us-east-1.amazonaws.com',
         expectedWithoutTrustProxy: 'b5gee6dacf.execute-api.us-east-1.amazonaws.com',
      },
      {
         host: 'b5gee6dacf.execute-api.us-east-1.amazonaws.com:443',
         expectedWithTrustProxy: 'b5gee6dacf.execute-api.us-east-1.amazonaws.com',
         expectedWithoutTrustProxy: 'b5gee6dacf.execute-api.us-east-1.amazonaws.com',
      },
      {
         host: 'b5gee6dacf.execute-api.us-east-1.amazonaws.com',
         xForwardedHost: 'api.example.com',
         expectedWithTrustProxy: 'api.example.com',
         expectedWithoutTrustProxy: 'b5gee6dacf.execute-api.us-east-1.amazonaws.com',
      },
      {
         host: 'b5gee6dacf.execute-api.us-east-1.amazonaws.com:443',
         xForwardedHost: 'api.example.com',
         expectedWithTrustProxy: 'api.example.com',
         expectedWithoutTrustProxy: 'b5gee6dacf.execute-api.us-east-1.amazonaws.com',
      },
      {
         host: 'b5gee6dacf.execute-api.us-east-1.amazonaws.com',
         xForwardedHost: 'api.example.com:433',
         expectedWithTrustProxy: 'api.example.com',
         expectedWithoutTrustProxy: 'b5gee6dacf.execute-api.us-east-1.amazonaws.com',
      },
      {
         host: 'b5gee6dacf.execute-api.us-east-1.amazonaws.com:443',
         xForwardedHost: 'api.example.com:443',
         expectedWithTrustProxy: 'api.example.com',
         expectedWithoutTrustProxy: 'b5gee6dacf.execute-api.us-east-1.amazonaws.com',
      },
   ];

   it('parses proper values - APIGW', () => {
      _.each(testCases, (testCase) => {
         let evt: RequestEvent = apiGatewayRequest(),
               req;

         evt.headers.Host = testCase.host;

         if (testCase.xForwardedHost) {
            evt.headers['X-Forwarded-Host'] = testCase.xForwardedHost;
            evt.multiValueHeaders['X-Forwarded-Host'] = [ testCase.xForwardedHost ];
         } else {
            delete evt.headers['X-Forwarded-Host'];
            delete evt.multiValueHeaders['X-Forwarded-Host'];
         }

         app.enable('trust proxy');
         req = new Request(app, evt, handlerContext());
         expect(req.hostname).to.eql(testCase.expectedWithTrustProxy);

         app.disable('trust proxy');
         req = new Request(app, evt, handlerContext());
         expect(req.hostname).to.eql(testCase.expectedWithoutTrustProxy);
      });
   });

   it('parses proper values - ALB', () => {
      _.each(testCases, (testCase) => {
         let req;

         _.each([ albRequest(), albMultiValHeadersRequest() ], (evt) => {
            if (evt.headers) {
               evt.headers.host = testCase.host;
               if (testCase.xForwardedHost) {
                  evt.headers['X-Forwarded-Host'] = testCase.xForwardedHost;
               } else {
                  delete evt.headers['X-Forwarded-Host'];
               }
            }
            if (evt.multiValueHeaders) {
               evt.multiValueHeaders.host = [ testCase.host ];
               if (testCase.xForwardedHost) {
                  evt.multiValueHeaders['X-Forwarded-Host'] = [ testCase.xForwardedHost ];
               } else {
                  delete evt.multiValueHeaders['X-Forwarded-Host'];
               }
            }

            app.enable('trust proxy');
            req = new Request(app, evt, handlerContext());
            expect(req.hostname).to.eql(testCase.expectedWithTrustProxy);

            app.disable('trust proxy');
            req = new Request(app, evt, handlerContext());
            expect(req.hostname).to.eql(testCase.expectedWithoutTrustProxy);
         });
      });
   });

});

Consider adding a 'prepare' script to build when npm installing from git repo

With lambda-express in early development, features and fixes are getting added and need to be tested faster than new versions are being cut. As such, it would be handy to be able to
install lambda-express directly from the git repo. However, due to the build process and needing the dist files, this isn't currently possible using npm i <repo>. Fortunately, a prepare script was added in npm 5. This script is ran when installing from a git repo and can be used to build the needed dist files.

More info: https://blog.jim-nielsen.com/2018/installing-and-building-an-npm-package-from-github/#installing-and-building-packages-with-npm-from-github

HEAD route is not automatically added for GET routes

For all GET routes, express will add support for HEAD requests automatically if a HEAD route is not already defined. lambda-express does not do this. At this time you must manually add the HEAD route.

Express docs: https://expressjs.com/en/api.html#router.METHOD

The router.get() function is automatically called for the HTTP HEAD method in addition to the GET method if router.head() was not called for the path before router.get().

Express sample:

$ cat index.js
const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => res.send('Hello World!'))

app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))

$ curl --head http://localhost:3000
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 12
ETag: W/"c-Lve95gjOVATpfV8EL5X4nxwjKHE"
Date: Sat, 11 Jul 2020 01:40:25 GMT
Connection: keep-alive

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.