Serverless-offline: httpApi does not support $default route

Created on 29 Oct 2020  ยท  2Comments  ยท  Source: dherault/serverless-offline

Bug Report

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.0
  • serverless-offline version: v6.8.0
  • node.js version: v12.18.3
  • OS: macOS 10.15.7

Most helpful comment

I 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.

All 2 comments

I 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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stunningpixels picture stunningpixels  ยท  3Comments

mattmeye picture mattmeye  ยท  4Comments

yareyaredesuyo picture yareyaredesuyo  ยท  4Comments

stonebraker picture stonebraker  ยท  3Comments

dnalborczyk picture dnalborczyk  ยท  3Comments