@trenskow/app 0.5.10 → 0.5.11
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.
- package/lib/endpoint.js +16 -10
- package/package.json +1 -1
package/lib/endpoint.js
CHANGED
|
@@ -178,16 +178,22 @@ export default class Endpoint extends Router {
|
|
|
178
178
|
|
|
179
179
|
async _route(path, context, next, idx = 0) {
|
|
180
180
|
|
|
181
|
-
if (idx === this._layers.length
|
|
181
|
+
if (idx === this._layers.length) {
|
|
182
182
|
|
|
183
|
-
|
|
184
|
-
.filter((layer) => layer.type === 'method')
|
|
185
|
-
.map((layer) => layer.method.toUpperCase())
|
|
186
|
-
.filter((value, index, array) => array.indexOf(value) === index);
|
|
183
|
+
if (path.isLast) {
|
|
187
184
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
185
|
+
const methods = this._layers
|
|
186
|
+
.filter((layer) => layer.type === 'method')
|
|
187
|
+
.map((layer) => layer.method.toUpperCase())
|
|
188
|
+
.filter((value, index, array) => array.indexOf(value) === index);
|
|
189
|
+
|
|
190
|
+
if (methods.length) {
|
|
191
|
+
context.response.headers.allow = methods.join(', ');
|
|
192
|
+
throw new ApiError.MethodNotAllowed();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
} else {
|
|
196
|
+
throw new ApiError.NotFound();
|
|
191
197
|
}
|
|
192
198
|
|
|
193
199
|
}
|
|
@@ -242,8 +248,8 @@ export default class Endpoint extends Router {
|
|
|
242
248
|
if (typeof layer.transform === 'function') {
|
|
243
249
|
context.parameters[layer.name] = await layer.transform(
|
|
244
250
|
Object.fromEntries([
|
|
245
|
-
[
|
|
246
|
-
[
|
|
251
|
+
['context', context],
|
|
252
|
+
[layer.name, component]
|
|
247
253
|
])
|
|
248
254
|
);
|
|
249
255
|
}
|