Comparing version 4.1.0 to 4.2.0
{ | ||
"name": "wegweiser", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "A router for Quinn", | ||
@@ -30,5 +30,5 @@ "main": "wegweiser.js", | ||
"dependencies": { | ||
"footnote": "^1.0.0", | ||
"footnote": "^1.1.0", | ||
"routington": "^1.0.3" | ||
} | ||
} |
@@ -35,4 +35,9 @@ # Wegweiser | ||
const router = createRouter(simpleHandler, PretendingItsJava); | ||
// router is a quinn handler: request => response | ||
const objectOrInstance { | ||
@GET('/object/:op') | ||
getObject(req, { op }) { return respond.json({ op }); } | ||
} | ||
const router = // router is a quinn handler: request => response | ||
createRouter(simpleHandler, PretendingItsJava, objectOrInstance); | ||
``` | ||
@@ -49,4 +54,6 @@ | ||
Each argument to this function should either be an annotated function | ||
or a class with annotated methods. | ||
Each argument to this function should be an annotated function, | ||
a class with annotated methods, | ||
or an object with annoated methods. | ||
Both for objects and classes the prototype chain will be scanned. | ||
Routes have to be unambiguous. | ||
@@ -53,0 +60,0 @@ If the same method and path combination is configured twice, |
@@ -26,5 +26,5 @@ 'use strict'; | ||
const constructAndHandle = function constructAndHandle(req) { | ||
const constructAndHandle = function constructAndHandle(req, params) { | ||
const instance = new ctor(req); | ||
return instance[key].apply(instance, arguments); | ||
return instance[key](req, params); | ||
}; | ||
@@ -36,2 +36,13 @@ | ||
return constructAndHandle; | ||
} else if (result.ctx !== null && typeof result.ctx === 'object') { | ||
const ctx = result.ctx, key = result.key; | ||
const applyHandlerToContext = function applyHandlerToContext(req, params) { | ||
return ctx[key](req, params); | ||
}; | ||
applyHandlerToContext.ctx = ctx; | ||
applyHandlerToContext.key = key; | ||
return applyHandlerToContext; | ||
} | ||
@@ -38,0 +49,0 @@ return result.target; |
7639
81
135
Updatedfootnote@^1.1.0