Currently, serverless works with API Gateway Http Api's $default route by giving '*' as the event name. i.e.
functions:
myFunction:
handler: src/index.handler
events:
- httpApi:
method: '*'
path: '*'
authorizer:
name: jwtAuthorizer
Deployed to AWS this gives you the special catch all route $default. With Serverless-offline, this configuration gives me the following error:
{"currentRoute":"get - /api/users","error":"Serverless-offline: route not found.","existingRoutes":["* - /*"]}
Expected behavior/code
I expect serverless-offline to create a special catch all route. It's important the catch all route is a lower priority than any other defined routes. i.e. OPTIONS /{proxy+} should continue to work while any other route should hit the $default route.
I'm able to manually create a catchall route but the priority doesn't work the same way it works with real API Gateway. A possible workaround would be manually creating a catch all just for the local stage but I haven't figured out a way to do that.
Environment
serverless version: v2.9.0serverless-offline version: v6.8.0node.js version: v12.18.3OS: macOS 10.15.7I was able to work around this issue for now. If I set my path to path: ${env:CATCHALL_ROUTE, '*'} where CATCHALL_ROUTE='/{proxy+}' then I'm able to deploy a $default route and use that catch all locally.
Thanks for this tip! I've found that serverless-offline is _also_ prepending the /dev (API Gateway default stage) to the URL.
$ serverless offline
Serverless: Running "serverless" installed locally (in service node_modules)
offline: Starting Offline: dev/us-east-1.
offline: Offline [http for lambda] listening on http://localhost:3002
offline: Function names exposed for local invocation by aws-sdk:
* app: ExampleService-dev-app
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โ * | http://localhost:3000/dev/{proxy*} โ
โ POST | http://localhost:3000/2015-03-31/functions/app/invocations โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
offline: [HTTP] server ready: http://localhost:3000 ๐
I've added this to my config to work around it:
custom:
serverless-offline:
noPrependStageInUrl: true
Was this the case with your config as well? I was trying to figure out where in the code here the stage was being added for HTTP API - maybe related to this issue?
Most helpful comment
I was able to work around this issue for now. If I set my path to
path: ${env:CATCHALL_ROUTE, '*'}whereCATCHALL_ROUTE='/{proxy+}'then I'm able to deploy a$defaultroute and use that catch all locally.