Service class architecture silently ignores duplicate routes
- Dominant language
- JavaScript
- Stars
- 27.2k
- Forks
- 5.6k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 46
Description
This is a bit of a contrived example, but if I declare something like:
```js
class VersionService1 extends BaseJsonService {
//stuff
static get url() {
return {
base: 'someroute/v',
format: '(.+)',
capture: ['param'],
}
}
}
class VersionService2 extends BaseJsonService {
//stuff
static get url() {
return {
base: 'someroute/v',
format: '(.+)',
capture: ['param'],
}
}
}
module.exports = {
VersionService1,
VersionService2,
}
```
`VersionService1` and `VersionService2` are both trying to mount on the same route. When we start the server, one wins and one loses (I guess the order we register the services in is important here) but it doesn't throw an error. In the example above, it is pretty easy to debug, but once you've got services spread across multiple files this condition could become quite hard to detect.
It would be a nice safeguard if we added a check when we register the service classes which throws an error if we have declared any duplicate or conflicting routes.
Contributor guide
Research direction
Start by tracing where service classes are registered and their routes are mounted, then reproduce the duplicate-route example from the issue. The work is done when registration detects duplicate or conflicting routes and raises an error instead of silently selecting one.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100