@vendia/serverless-express
Advanced tools
Comparing version 4.7.1 to 4.8.0
{ | ||
"name": "@vendia/serverless-express", | ||
"version": "4.7.1", | ||
"version": "4.8.0", | ||
"description": "This library enables you to utilize AWS Lambda and Amazon API Gateway to respond to web and API requests using your existing Node.js application framework.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -11,3 +11,3 @@ # Serverless Express by [Vendia](https://vendia.net/) | ||
Run REST APIs and other web applications using your existing [Node.js](https://nodejs.org/) application framework (Express, Koa, Hapi, Sails, etc.), on top of [AWS Lambda](https://aws.amazon.com/lambda/) and [Amazon API Gateway](https://aws.amazon.com/api-gateway/). | ||
Run REST APIs and other web applications using your existing [Node.js](https://nodejs.org/) application framework (Express, Koa, Hapi, Sails, etc.), on top of [AWS Lambda](https://aws.amazon.com/lambda/) and [Amazon API Gateway](https://aws.amazon.com/api-gateway/) or [Azure Function](https://docs.microsoft.com/en-us/azure/azure-functions/). | ||
@@ -29,4 +29,6 @@ ```bash | ||
## Minimal Lambda handler wrapper | ||
## AWS | ||
### Minimal Lambda handler wrapper | ||
The only AWS Lambda specific code you need to write is a simple handler like below. All other code you can write as you normally do. | ||
@@ -41,3 +43,3 @@ | ||
## Async setup Lambda handler | ||
### Async setup Lambda handler | ||
@@ -76,2 +78,41 @@ If your application needs to perform some common bootstrap tasks such as connecting to a database before the request is forward to the API, you can use the following pattern (also available in [this example](https://github.com/vendia/serverless-express/blob/mainline/examples/basic-starter-api-gateway-v2/src/lambda-async-setup.js)): | ||
## Azure | ||
### Async Azure Function (v3) handler wrapper | ||
The only Azure Function specific code you need to write is a simple `index.js` and a `function.json` like below. | ||
```js | ||
// index.js | ||
const serverlessExpress = require('@vendia/serverless-express') | ||
const app = require('./app') | ||
const cachedServerlessExpress = serverlessExpress({ app }) | ||
module.exports = async function (context, req) { | ||
return cachedServerlessExpress(context, req) | ||
} | ||
``` | ||
The _out-binding_ parameter `"name": "$return"` is important for Serverless Express to work. | ||
```json | ||
// function.json | ||
{ | ||
"bindings": [ | ||
{ | ||
"authLevel": "anonymous", | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req", | ||
"route": "{*segments}" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} | ||
``` | ||
## 4.x | ||
@@ -78,0 +119,0 @@ |
@@ -8,2 +8,3 @@ const awsApiGatewayV1EventSource = require('./aws/api-gateway-v1') | ||
const awsDynamoDbEventSource = require('./aws/dynamodb') | ||
const azureHttpFunctionV3EventSource = require('./azure/http-function-runtime-v3') | ||
const awsEventBridgeEventSource = require('./aws/eventbridge') | ||
@@ -25,2 +26,4 @@ | ||
return awsSnsEventSource | ||
case 'AZURE_HTTP_FUNCTION_V3': | ||
return azureHttpFunctionV3EventSource | ||
case 'AWS_SQS': | ||
@@ -27,0 +30,0 @@ return awsSqsEventSource |
@@ -90,2 +90,13 @@ const url = require('url') | ||
} | ||
if (event.traceContext) { | ||
const functionsExtensionVersion = process.env.FUNCTIONS_EXTENSION_VERSION | ||
if (!functionsExtensionVersion) { | ||
console.warn('The environment variable \'FUNCTIONS_EXTENSION_VERSION\' is not set. Only the function runtime \'~3\' is supported.') | ||
} else if (functionsExtensionVersion !== '~3') { | ||
console.warn('Only the function runtime \'~3\' is supported.') | ||
} | ||
return 'AZURE_HTTP_FUNCTION_V3' | ||
} | ||
if ( | ||
@@ -133,2 +144,13 @@ event.version && | ||
const parseCookie = (str) => | ||
str.split(';') | ||
.map((v) => v.split('=')) | ||
.reduce((acc, v) => { | ||
if (!v[1]) { | ||
return acc | ||
} | ||
acc[decodeURIComponent(v[0].trim().toLowerCase())] = decodeURIComponent(v[1].trim()) | ||
return acc | ||
}, {}) | ||
module.exports = { | ||
@@ -141,3 +163,4 @@ getPathWithQueryStringParams, | ||
getCommaDelimitedHeaders, | ||
emptyResponseMapper | ||
emptyResponseMapper, | ||
parseCookie | ||
} |
@@ -66,3 +66,4 @@ const util = require('util') | ||
eventSourceName !== 'AWS_API_GATEWAY_V1' && | ||
eventSourceName !== 'AWS_API_GATEWAY_V2' | ||
eventSourceName !== 'AWS_API_GATEWAY_V2' && | ||
eventSourceName !== 'AZURE_HTTP_FUNCTION_V3' | ||
) { | ||
@@ -69,0 +70,0 @@ resolver.fail({ error }) |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
66129
38
1248
353
2