dherault / dherault/serverless-offline

Enable mixed API usage with same routes

Open
#1,737 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5.3k
Forks
811
Avg merge
2d 4h
Merged PRs (30d)
3

Description

## 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:
```yaml
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:
```yaml
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
```yaml
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.
```yaml
custom:
serverless-offline:
ignoreEvents:
- httpApi
```

3. Prepend event in url?
```yaml
custom:
serverless-offline:
prependEventInUrl: true
```

Contributor guide

Open the contributing guide

Research direction

The issue does not name a source file, test, or entry point. Start by locating Serverless Offline's route registration and conflict handling, then determine and document one supported way for REST and HTTP API events to share routes, including tests for the stated configurations.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.