@tahminator/sapling 1.3.1 → 1.3.3
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.
|
@@ -14,7 +14,6 @@ import { _getRoutes } from "./route";
|
|
|
14
14
|
import { Sapling } from "../helper/sapling";
|
|
15
15
|
import { Html404ErrorPage } from "../html/404";
|
|
16
16
|
import { ResponseEntity, RedirectView } from "../helper";
|
|
17
|
-
const _usedPrefixes = new Set();
|
|
18
17
|
export const _ControllerRegistry = new WeakMap();
|
|
19
18
|
/**
|
|
20
19
|
* Registers a class as an HTTP controller and registers its routes.
|
|
@@ -28,10 +27,6 @@ export function Controller({ prefix = "", deps = [] } = {
|
|
|
28
27
|
}) {
|
|
29
28
|
return (target) => {
|
|
30
29
|
const targetClass = target;
|
|
31
|
-
if (_usedPrefixes.has(prefix)) {
|
|
32
|
-
throw new Error(`The prefix "${prefix}" is already in use by another constructor. Please resolve this issue.`);
|
|
33
|
-
}
|
|
34
|
-
_usedPrefixes.add(prefix);
|
|
35
30
|
const router = Router();
|
|
36
31
|
const routes = _getRoutes(target);
|
|
37
32
|
const usedRoutes = new Set();
|
|
@@ -54,6 +49,10 @@ export function Controller({ prefix = "", deps = [] } = {
|
|
|
54
49
|
const methodName = methodResolve[method];
|
|
55
50
|
router[methodName](fp, (request, response, next) => __awaiter(this, void 0, void 0, function* () {
|
|
56
51
|
const result = yield fn.bind(controllerInstance)(request, response, next);
|
|
52
|
+
// Middleware (USE) should not send responses, just call next()
|
|
53
|
+
if (method === "USE") {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
57
56
|
if (result instanceof ResponseEntity) {
|
|
58
57
|
response
|
|
59
58
|
.contentType("application/json")
|