dherault / serverless-offline

Emulate AWS λ and API Gateway locally when developing your Serverless project
MIT License
5.16k stars 794 forks source link

Enable mixed API usage with same routes #1737

Open JaroVDH opened 9 months ago

JaroVDH commented 9 months ago

Feature Request

This is an uncommon use case, but it's possible to have multiple endpoints with the same route if you have both REST & HTTP in use. For example, if you're migrating from one to the other and run them in parallel:

functions:
  main:
    handler: src/index.handle
    events:
      - http:
          path: /
      - httpApi:
          path: /

Or if you have two fully distinct APIs that just happen to have matching paths in routes:

functions:
  oneApi:
    handler: src/one/index.handle
    events:
      - http:
          path: /{proxy}
  otherApi:
    handler: src/other/index.handle
    events:
      - httpApi:
          path: /{proxy}

Currently Serverless Offline will fail with AssertError: New route X conflicts with existing X.

Expected behavior I'm not sure what the best way to handle this would be. Some ways this could be handled:

  1. Custom prefix per event type

    custom:
    serverless-offline:
    prefix:
      http: "rest"
      httpApi: "http"

    Overloading the prefix type would make the documentation more confusing, though.

  2. Ignoring some event types

You could then run multiple instances of sls offline which ignore different sets of events.

custom:
  serverless-offline:
    ignoreEvents:
      - httpApi
  1. Prepend event in url?
    custom:
    serverless-offline:
    prependEventInUrl: true