Skip to content

Commit

Permalink
fix: improved alb request query string parsing
Browse files Browse the repository at this point in the history
updated docs
  • Loading branch information
Inqnuam committed Nov 5, 2023
1 parent 856492b commit ff0cec7
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 72 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-aws-lambda",
"version": "4.6.5",
"version": "4.6.6",
"description": "AWS Application Load Balancer and API Gateway - Lambda dev tool for Serverless. Allows Express synthax in handlers. Supports packaging, local invoking and offline ALB, APG, S3, SNS, SQS, DynamoDB Stream server mocking.",
"author": "Inqnuam",
"license": "MIT",
Expand Down
27 changes: 6 additions & 21 deletions resources/defineConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export default defineConfig({
});
```

### Create a custom plugin which may be used inside defineConfig's `plugins`
#### Create a custom plugin which may be used inside defineConfig's `plugins`

```js
/**
* @type {import("serverless-aws-lambda/defineConfig").SlsAwsLambdaPlugin}
*/
const myCustomPlugin = {
import { defineConfig } from "serverless-aws-lambda/defineConfig";
import type { SlsAwsLambdaPlugin } from "serverless-aws-lambda/defineConfig";
const myCustomPlugin:SlsAwsLambdaPlugin = {
name: "my-custom-plugin",
onInit: async function () {
// do something
Expand Down Expand Up @@ -81,7 +81,7 @@ export default defineConfig({
module.exports = defineConfig({
export default defineConfig({
esbuild: {
target: "es2020",
},
Expand All @@ -92,18 +92,3 @@ module.exports = defineConfig({
plugins: [myCustomPlugin],
});
```

`defineConfig` can be imported as ESM as well.

```js
import { defineConfig } from "serverless-aws-lambda/defineConfig";
import { sqsPlugin } from "serverless-aws-lambda/sqs";
export default defineConfig({
offline: {
staticPath: "./.aws_lambda",
port: 9999,
},
plugins: [sqsPlugin()],
});
```
80 changes: 38 additions & 42 deletions resources/offline.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,30 @@ Set offline static path, custom port and add request listeners:

```js
// config.js
module.exports = ({ lambdas, isDeploying, isPackaging, setEnv, stage, port }) => {
/**
* @type {import("serverless-aws-lambda").Config}
*/
return {
esbuild: {
//...
import { defineConfig } from "serverless-aws-lambda/defineConfig";

export default defineConfig({
esbuild: {
//...
},
offline: {
staticPath: "./public",
port: 9999,
onReady: (port) => {
console.log("We are ready to listen on", port);
},
offline: {
staticPath: "./public",
port: 9999,
onReady: (port) => {
console.log("We are ready to listen on", port);
},
request: [
{
filter: /^\/__routes(\/)?$/, // filters request when request URL match /__routes
callback: (req, res) => {
// node http request Incoming Message and Response object
res.statusCode = 404;
res.end(`${req.url} not found`);
},
request: [
{
filter: /^\/__routes(\/)?$/, // filters request when request URL match /__routes
callback: (req, res) => {
// node http request Incoming Message and Response object
res.statusCode = 404;
res.end(`${req.url} not found`);
},
],
},
};
};
},
],
},
});
```

### virtualEnvs
Expand Down Expand Up @@ -70,24 +67,23 @@ functions:
```
```js
// config.js
module.exports = ({ lambdas, isDeploying, isPackaging, setEnv, stage, port }) => {
return {
esbuild: {
// ...
},
offline: {
// ...
},
buildCallback: async (result) => {
const foundLambda = lambdas.find((x) => x.name == "players");
import { defineConfig } from "serverless-aws-lambda/defineConfig";

if (foundLambda) {
console.log(foundLambda.virtualEnvs);
}
},
};
};
export default defineConfig({
esbuild: {
// ...
},
offline: {
// ...
},
buildCallback: async (result) => {
const foundLambda = lambdas.find((x) => x.name == "players");

if (foundLambda) {
console.log(foundLambda.virtualEnvs);
}
},
});
```

## Run serverless-aws-lambda programmatically
Expand Down
6 changes: 3 additions & 3 deletions resources/sns.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Import the plugin inside your defineConfig.

```js
// config.js
const { defineConfig } = require("serverless-aws-lambda/defineConfig");
const { snsPlugin } = require("serverless-aws-lambda/sns");
import { defineConfig } from "serverless-aws-lambda/defineConfig";
import { snsPlugin } = from "serverless-aws-lambda/sns";

module.exports = defineConfig({
export default defineConfig({
plugins: [snsPlugin()],
});
```
Expand Down
6 changes: 3 additions & 3 deletions resources/sqs.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ Import the plugin inside your defineConfig.

```js
// config.js
const { defineConfig } = require("serverless-aws-lambda/defineConfig");
const { sqsPlugin } = require("serverless-aws-lambda/sqs");
import { defineConfig } from "serverless-aws-lambda/defineConfig";
import { sqsPlugin } = from "serverless-aws-lambda/sqs";

module.exports = defineConfig({
export default defineConfig({
plugins: [sqsPlugin(config)],
});
```
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/lambda/events/alb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ export class AlbRequestHandler extends CommonEventGenerator {
const queryComponents = queryString.split("&");

queryComponents.forEach((c) => {
const [key, value] = c.split("=");
queryStringComponents[key] = value;
const [key, ...value] = c.split("=");
queryStringComponents[key] = value.join("=");
});

delete queryStringComponents.x_mock_type;
Expand Down

0 comments on commit ff0cec7

Please sign in to comment.