Skip to content

Commit 76101be

Browse files
committed
fix: send events on v2.0 format
1 parent f89ccf6 commit 76101be

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

.vscode/launch.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Launch AWS Nodejs",
9+
"type": "node",
10+
"request": "launch",
11+
"cwd": "${workspaceFolder}/templates/aws-nodejs",
12+
"runtimeExecutable": "pnpm",
13+
"runtimeArgs": ["run-script", "start"]
14+
},
15+
{
16+
"name": "Launch AWS Nodejs ECMAScript",
17+
"type": "node",
18+
"request": "launch",
19+
"cwd": "${workspaceFolder}/templates/aws-nodejs-ecma-script",
20+
"runtimeExecutable": "pnpm",
21+
"runtimeArgs": ["run-script", "start"]
22+
},
23+
{
24+
"name": "Launch AWS Nodejs Typescript",
25+
"type": "node",
26+
"request": "launch",
27+
"cwd": "${workspaceFolder}/templates/aws-nodejs-typescript",
28+
"runtimeExecutable": "pnpm",
29+
"runtimeArgs": ["run-script", "start"]
30+
}
31+
]
32+
}

index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,21 @@ export default class ServerlessOfflineLambdaFunctionUrls {
3535
}, {})
3636
}
3737
getEvents(functions) {
38+
const stage = this.getStage()
3839
return Object.entries(functions).reduce((events, [functionKey, {handler}]) => {
39-
const path = `/${encodeURIComponent(functionKey)}`
40+
const path = `/${stage}/${encodeURIComponent(functionKey)}`
4041
return [
4142
...events,
42-
{functionKey, handler, http: {path, method: 'GET'}},
43-
{functionKey, handler, http: {path, method: 'POST'}},
43+
{functionKey, handler, http: {routeKey: `GET ${path}`, payload: '2.0', isHttpApi: true, path, method: 'GET'}},
44+
{functionKey, handler, http: {routeKey: `POST ${path}`, payload: '2.0', isHttpApi: true, path, method: 'POST'}},
4445
]
4546
}, [])
4647
}
48+
getStage() {
49+
return this.serverless.variables.options?.stage ?? this.configuration.provider?.stage
50+
}
4751
mergeServerlessOfflineOptions(options) {
48-
const stage = this.serverless.variables.options?.stage ?? this.configuration.provider?.stage
52+
const stage = this.getStage()
4953
const serverlessOfflineOptions = this.configuration?.custom?.['serverless-offline'] ?? {}
5054
return {
5155
...serverlessOfflineOptions,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-offline-lambda-function-urls",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"license": "ISC",
55
"description": "An extension off serverless-offline that adds support to lambda function urls",
66
"type": "module",

0 commit comments

Comments
 (0)