Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: serverless-express@5 #649

Open
wants to merge 7 commits into
base: mainline
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release-on-push-to-mainline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x, 18.x]
node-version: [18.x]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

node_modules/.bin/commitlint -e $GIT_PARAMS
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

node_modules/.bin/lint-staged
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm test
49 changes: 49 additions & 0 deletions __tests__/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const apiGatewayEventSource = eventSources.getEventSource({ eventSourceName: 'AW

test('getPathWithQueryStringParams: no params', () => {
const event = {
resource: '/',
path: '/foo/bar'
}
const pathWithQueryStringParams = serverlessExpressEventSourcesUtils.getPathWithQueryStringParams({ event })
Expand All @@ -18,6 +19,7 @@ test('getPathWithQueryStringParams: no params', () => {

test('getPathWithQueryStringParams: 1 param', () => {
const event = {
resource: '/',
path: '/foo/bar',
multiValueQueryStringParameters: {
bizz: 'bazz'
Expand All @@ -29,6 +31,7 @@ test('getPathWithQueryStringParams: 1 param', () => {

test('getPathWithQueryStringParams: to be url-encoded param', () => {
const event = {
resource: '/',
path: '/foo/bar',
multiValueQueryStringParameters: {
redirect_uri: 'http://lvh.me:3000/cb'
Expand All @@ -40,6 +43,7 @@ test('getPathWithQueryStringParams: to be url-encoded param', () => {

test('getPathWithQueryStringParams: 2 params', () => {
const event = {
resource: '/',
path: '/foo/bar',
multiValueQueryStringParameters: {
bizz: 'bazz',
Expand All @@ -52,6 +56,7 @@ test('getPathWithQueryStringParams: 2 params', () => {

test('getPathWithQueryStringParams: array param', () => {
const event = {
resource: '/',
path: '/foo/bar',
multiValueQueryStringParameters: {
bizz: [
Expand All @@ -64,8 +69,52 @@ test('getPathWithQueryStringParams: array param', () => {
expect(pathWithQueryStringParams).toEqual('/foo/bar?bizz=bazz&bizz=buzz')
})

test('getPathWithQueryStringParams: pathParameters.proxy', () => {
const event = {
resource: '/foo/{proxy+}',
path: '/foo/123',
pathParameters: {
proxy: '123'
}
}
const pathWithQueryStringParams = serverlessExpressEventSourcesUtils.getPathWithQueryStringParams({ event })
expect(pathWithQueryStringParams).toEqual('/123')
})

test('getPathWithQueryStringParams: customDomain and no path parameters', () => {
const event = {
resource: '/foo',
path: '/baz/foo',
requestContext: {
customDomain: {
basePathMatched: 'baz'
}
}
}
const pathWithQueryStringParams = serverlessExpressEventSourcesUtils.getPathWithQueryStringParams({ event })
expect(pathWithQueryStringParams).toEqual('/')
})

test('getPathWithQueryStringParams: customDomain and path parameters', () => {
const event = {
resource: '/foo/{proxy+}',
path: '/baz/foo/123',
pathParameters: {
proxy: '123'
},
requestContext: {
customDomain: {
basePathMatched: 'baz'
}
}
}
const pathWithQueryStringParams = serverlessExpressEventSourcesUtils.getPathWithQueryStringParams({ event })
expect(pathWithQueryStringParams).toEqual('/123')
})

function getReqRes (multiValueHeaders = {}) {
const event = {
resource: '/',
path: '/foo',
httpMethod: 'GET',
body: 'Hello serverless!',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import apiGatewayEvent from "../api-gateway-event.json";
import * as lambdaFunction from "../src/lambda";
import { Context, Callback } from "aws-lambda";
import type { Context, Callback } from "aws-lambda";

const context = {} as Context;

Expand Down
2 changes: 1 addition & 1 deletion examples/basic-starter-nestjs/src/lambda.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NestFactory } from '@nestjs/core';
import { ExpressAdapter } from '@nestjs/platform-express';
import serverlessExpress from '@vendia/serverless-express';
import { Context, Handler } from 'aws-lambda';
import type { Context, Handler } from 'aws-lambda';
import express from 'express';

import { AppModule } from './app.module';
Expand Down
4 changes: 2 additions & 2 deletions examples/sails-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
"author": "brett",
"license": "",
"engines": {
"node": "^12.4"
"node": ">=18"
}
}
}
Loading