Skip to content

Commit

Permalink
expose app.setRoute() to go with app.get, app.post etc; 0.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasq committed Apr 4, 2021
1 parent 56f6b6f commit cdd3bec
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ The app has properties
The app has methods
- `app.use(func)` - mw routing method. Calling app.use switches to running in routed mode,
`processRequest` will not be called. A four-argument function is used as the error handler,
else as the pre-middleware step. The router used if not provided is the built-in `rest.NanoRouter`.
else as the pre-middleware step. The router used if not provided is the built-in `rest.NanoRouter`.
- `app.get`, `app.post`, `app.put`, `app.del`, etc - mw routing methods
- `app.setRoute(path, method, mwStep)` - exposes the rest router setRoute() endpoint.
See `NanoRouter` and `router.js` below
- `app.onError(err, req, res, next)` - function called if the route handler encounters an error
not handled by the `'err'` step.
- `app.listen([portOrOptions], [callback])` - invoke rest.createServer with this app as the request
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ tests or benchmarks, check out the repo from https://github.com/andrasq/node-mic
Change Log
----------

- 0.9.2 - expose `app.setRoute()` along with app.get, app.post etc
- 0.9.1 - pretty-print error responses, handle path-not-routed errors with the configured mw
- 0.9.0 - have parseQuery also set `req.path` and `req.query`
- 0.8.3 - speed access to req.params et al, req.destroy() if bodySizeLimit exceeded
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "microrest",
"version": "0.9.1",
"version": "0.9.2",
"description": "tiny, quick, embeddable REST web framework",
"keywords": ["micro", "nano", "framework", "middleware", "REST", "embeddable", "fast"],
"main": "index.js",
Expand Down
5 changes: 3 additions & 2 deletions rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ function createHandler( options ) {
var httpMethods = [ 'options', 'get', 'head', 'post', 'put', 'delete', 'trace', 'connect', 'patch' ]
function useRouter() { return rest.router ? rest.router : rest.router = new Rest.NanoRouter() }
handler.use = function use(mw) { typeof mw === 'string' ? useRouter().setRoute(arguments[0], arguments[1]) : useRouter().setRoute(mw.length === 4 ? 'err' : 'use', mw); }
handler.setRoute = function setRoute(path, method, mw) { useRouter().setRoute(path, method.toUpperCase(), sliceMwArgs([], arguments, 2)) };
httpMethods.forEach(function(method) {
var fn = function( path, mw ) { useRouter().setRoute(path, method.toUpperCase(), sliceMwArgs(new Array(), arguments, 1)) };
// NOTE: node-v0.7 and older cannot delete fn.name, cannot redefine fn.name
var fn = function(path, mw) { handler.setRoute(path, method, sliceMwArgs(new Array(), arguments, 1)) };
// NOTE: node-v0.7 and older cannot delete fn.name, cannot change fn.name, but can defineProperty
handler[method] = Object.defineProperty(fn, 'name', { value: method });
})
handler.del = handler.delete;
Expand Down

0 comments on commit cdd3bec

Please sign in to comment.