Skip to content

Commit 254151c

Browse files
authored
feat: allow specifying HTTP verbs to expose (#3)
1 parent 76101be commit 254151c

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ plugins:
1919
```yaml
2020
serverless-offline:
2121
urlLambdaFunctionsHttpPort: 3003
22+
23+
# Optional - choose which HTTP verb(s) to enable. If omitted, GET and POST will be enabled
24+
urlLambdaFunctionsHttpVerbs:
25+
- GET
26+
- DELETE
2227
```
2328
24-
3. Configure a lambda url function. When you add the `url` option, the handler will expose it as a `GET/POST` HTTP endpoint(`/dev/ping`). The HTTP endpoint doesn't go through the API Gateway, which means that you can set your own `timeout` and it will respect it. Traditionally, the API Gateway would timeout after 30 seconds.
29+
3. Configure a lambda url function. When you add the `url` option, the handler will expose it as an HTTP endpoint(`/dev/ping`) with the verbs specified in `urlLambdaFunctionsHttpVerbs` or `GET` and `POST` if that setting is not specified. The HTTP endpoint doesn't go through the API Gateway, which means that you can set your own `timeout` and it will respect it. Traditionally, the API Gateway would timeout after 30 seconds.
2530

2631
```yaml
2732
ping:

index.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,23 @@ export default class ServerlessOfflineLambdaFunctionUrls {
3636
}
3737
getEvents(functions) {
3838
const stage = this.getStage()
39+
const verbs = this.configuration?.custom?.['serverless-offline']?.urlLambdaFunctionsHttpVerbs ?? [
40+
'GET',
41+
'POST'
42+
]
3943
return Object.entries(functions).reduce((events, [functionKey, {handler}]) => {
4044
const path = `/${stage}/${encodeURIComponent(functionKey)}`
41-
return [
42-
...events,
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'}},
45-
]
45+
return events.concat(verbs.map(v => ({
46+
functionKey,
47+
handler,
48+
http: {
49+
routeKey: `${verb} ${path}`,
50+
payload: '2.0',
51+
isHttpApi: true,
52+
path,
53+
method: verb
54+
}
55+
})))
4656
}, [])
4757
}
4858
getStage() {

0 commit comments

Comments
 (0)