@tahminator/sapling 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -34,7 +34,7 @@ export function Controller({ prefix = "", deps = [] } = {
|
|
|
34
34
|
_usedPrefixes.add(prefix);
|
|
35
35
|
const router = Router();
|
|
36
36
|
const routes = _getRoutes(target);
|
|
37
|
-
const
|
|
37
|
+
const usedRoutes = new Set();
|
|
38
38
|
_InjectableDeps.set(targetClass, deps);
|
|
39
39
|
const controllerInstance = _resolve(targetClass);
|
|
40
40
|
for (const { method, path, fnName } of routes) {
|
|
@@ -42,13 +42,14 @@ export function Controller({ prefix = "", deps = [] } = {
|
|
|
42
42
|
if (typeof fn !== "function")
|
|
43
43
|
continue;
|
|
44
44
|
const fp = prefix + path;
|
|
45
|
+
const routeKey = method + " " + fp;
|
|
45
46
|
// Only check for duplicates on non-middleware routes
|
|
46
|
-
// Middleware (USE) can have duplicate paths
|
|
47
|
-
if (method !== "USE" &&
|
|
48
|
-
throw new Error(`Duplicate route
|
|
47
|
+
// Middleware (USE) can have duplicate paths, and different HTTP methods can share paths
|
|
48
|
+
if (method !== "USE" && usedRoutes.has(routeKey)) {
|
|
49
|
+
throw new Error(`Duplicate route [${method}] "${fp}" detected in controller "${target.name}"`);
|
|
49
50
|
}
|
|
50
51
|
if (method !== "USE") {
|
|
51
|
-
|
|
52
|
+
usedRoutes.add(routeKey);
|
|
52
53
|
}
|
|
53
54
|
const methodName = methodResolve[method];
|
|
54
55
|
router[methodName](fp, (request, response, next) => __awaiter(this, void 0, void 0, function* () {
|