The ALB event documentation allows specifying multiple methods. However if I try to run my configuration using serverless-offline, only the top method is used.
Current Behavior
Sample Code
file: serverless.yml
service: my-service
plugins:
- serverless-webpack
- serverless-offline
custom:
serverless-offline:
httpPort: 3000
host: 0.0.0.0
provider:
name: aws
runtime: nodejs18.x
functions:
myFunc:
handler: src/alb.myFunc
events:
- alb:
listenerArn: <some value, probably not important>
priority: <some other value, probably not important>
conditions:
host: <host>
path: /api/*
method:
- POST
- GET
Expected behavior/code
When I run sls offline I expect there to be two listeners on the /{stage}/api path but instead I only get one i.e.
What I currently see:
┌──────────────────────────────────────────────────────────────────────────────┐
│ │
│ POST | http://0.0.0.0:3003/dev/api/{0} │
│ POST | http://0.0.0.0:3003/2015-03-31/functions/myFunc/invocations │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
What I was expecting to see:
┌──────────────────────────────────────────────────────────────────────────────┐
│ │
│ POST | http://0.0.0.0:3003/dev/api/{0} │
│ GET | http://0.0.0.0:3003/dev/api/{0} │
│ POST | http://0.0.0.0:3003/2015-03-31/functions/myFunc/invocations │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
a possible solution would be to not select the first method but keep the methods as an array then iterate through each to create an hapiHandler and route
I don't currently have time to make a PR but if no one else can I can come back to this when time permits.
Bug Report
The ALB event documentation allows specifying multiple methods. However if I try to run my configuration using serverless-offline, only the top method is used.
Current Behavior
Sample Code
Expected behavior/code
When I run
sls offline
I expect there to be two listeners on the /{stage}/api path but instead I only get one i.e.What I currently see:
What I was expecting to see:
Environment
serverless
version: [e.g. v3.28.1]serverless-offline
version: [e.g. v13.3.3]node.js
version: [e.g. v18.19.1]OS
: Ubuntu 22.04.4Possible Solution
The issue seems to be at https://github.com/dherault/serverless-offline/blob/master/src/events/alb/HttpServer.js#L297 where the method is selected as
a possible solution would be to not select the first method but keep the methods as an array then iterate through each to create an hapiHandler and route
I don't currently have time to make a PR but if no one else can I can come back to this when time permits.