badges / badges/shields

Service class architecture silently ignores duplicate routes

Open
#2,155 2 comments 1 reaction 0 assignees View on GitHub
core developer-experience
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.