Permalink
Browse files

Merge branch '5.x' into 5.x-docs

  • Loading branch information...
2 parents 465ef6a + c56d42c commit 4e9c327d7749c52b9fcb6e5026b7d2b4936d834b @yunong yunong committed on GitHub Dec 10, 2016
Showing with 187 additions and 39 deletions.
  1. +44 −7 README.md
  2. +3 −8 docs/pages/components/plugins.md
  3. +1 −1 docs/pages/index.md
  4. +9 −7 examples/dtrace/demo.js
  5. +1 −1 lib/bunyan_helper.js
  6. +1 −1 lib/request.js
  7. +40 −5 lib/router.js
  8. +2 −2 lib/server.js
  9. +5 −5 package.json
  10. +22 −0 test/router.test.js
  11. +59 −2 test/server.test.js
View
@@ -1,3 +1,29 @@
+<!-- Please don't remove this: Grab your social icons from https://github.com/carlsednaoui/gitsocial -->
+
+<!-- display the social media buttons in your README -->
+
+[![alt text][1.1]][1]
+
+
+<!-- links to social media icons -->
+<!-- no need to change these -->
+
+<!-- icons with padding -->
+
+[1.1]: http://i.imgur.com/tXSoThF.png (twitter icon with padding)
+
+<!-- icons without padding -->
+
+[1.2]: http://i.imgur.com/wWzX9uB.png (twitter icon without padding)
+
+
+<!-- links to your social media accounts -->
+<!-- update these accordingly -->
+
+[1]: http://www.twitter.com/restifyjs
+
+<!-- Please don't remove this: Grab your social icons from https://github.com/carlsednaoui/gitsocial -->
+
![restify](/../gh-images/logo/png/restify_logo_black_transp_288x288.png?raw=true "restify")
[![Build Status](https://travis-ci.org/restify/node-restify.svg)](https://travis-ci.org/restify/node-restify)
@@ -6,8 +32,16 @@
[![bitHound Score](https://www.bithound.io/github/restify/node-restify/badges/score.svg)](https://www.bithound.io/github/restify/node-restify/master)
[![NSP Status](https://img.shields.io/badge/NSP%20status-no%20vulnerabilities-green.svg)](https://travis-ci.org/restify/node-restify)
-[restify](http://restify.com) is a smallish framework for building REST APIs.
-For full details, see http://restify.com
+
+[restify](http://restify.com) is a framework, utilizing
+[connect](https://github.com/senchalabs/connect) style middleware for building
+REST APIs. For full details, see http://restify.com
+
+Follow restify on [![alt text][1.2]][1]
+
+Join us on IRC at `irc.freenode.net` in the `#restify` channel for real-time
+chat and support.
+
# Usage
@@ -16,14 +50,16 @@ For full details, see http://restify.com
var restify = require('restify');
var plugins = require('restify-plugins');
-var server = restify.createServer({
+
+const server = restify.createServer({
name: 'myapp',
version: '1.0.0'
});
server.use(plugins.acceptParser(server.acceptable));
server.use(plugins.queryParser());
server.use(plugins.bodyParser());
+
server.get('/echo/:name', function (req, res, next) {
res.send(req.params);
return next();
@@ -40,6 +76,7 @@ var assert = require('assert');
var clients = require('restify-clients');
var client = clients.createJsonClient({
+
url: 'http://localhost:8080',
version: '~1.0'
});
@@ -51,13 +88,13 @@ client.get('/echo/mark', function (err, req, res, obj) {
```
# Installation
-
- $ npm install restify
-
+```bash
+$ npm install restify
+```
## License
The MIT License (MIT)
-Copyright (c) 2012 Mark Cavage
+Copyright (c) 2016 restify
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
@@ -146,7 +146,7 @@ server.use(restify.bodyParser({
},
keepExtensions: false,
uploadDir: os.tmpdir(),
- multiples: true
+ multiples: true,
hash: 'sha1',
rejectUnknown: true
}));
@@ -159,7 +159,7 @@ Options:
* `mapFiles` - if `req.params` should be filled with the contents of files sent through a multipart request. [formidable](https://github.com/felixge/node-formidable) is used internally for parsing, and a file is denoted as a multipart part with the `filename` option set in its `Content-Disposition`. This will only be performed if `mapParams` is true.
* `overrideParams` - if an entry in `req.params` should be overwritten by the value in the body if the names are the same. For instance, if you have the route `/:someval`, and someone posts an `x-www-form-urlencoded` Content-Type with the body `someval=happy` to `/sad`, the value will be `happy` if `overrideParams` is `true`, `sad` otherwise.
* `multipartHandler` - a callback to handle any multipart part which is not a file. If this is omitted, the default handler is invoked which may or may not map the parts into `req.params`, depending on the `mapParams`-option.
-* `multipartFileHandler` - a callback to handle any multipart file. It will be a file if the part have a `Content-Disposition` with the `filename` parameter set. This typically happens when a browser sends a form and there is a parameter similar to `<input type="file" />`. If this is not provided, the default behaviour is to map the contents into `req.params`.
+* `multipartFileHandler` - a callback to handle any multipart file. It will be a file if the part has a `Content-Disposition` with the `filename` parameter set. This typically happens when a browser sends a form and there is a parameter similar to `<input type="file" />`. If this is not provided, the default behaviour is to map the contents into `req.params`.
* `keepExtensions` - if you want the uploaded files to include the extensions of the original files (multipart uploads only). Does nothing if `multipartFileHandler` is defined.
* `uploadDir` - Where uploaded files are intermediately stored during transfer before the contents is mapped into `req.params`. Does nothing if `multipartFileHandler` is defined.
* `multiples` - if you want to support html5 multiple attribute in upload fields.
@@ -454,7 +454,7 @@ record lookling like this:
},
"secure": false,
"level": 30,
- "msg": GetFoo handled: 200",
+ "msg": "GetFoo handled: 200",
"time": "2012-02-07T20:30:31.896Z",
"v": 0
}
@@ -476,8 +476,3 @@ SERVER.on('auditlog', function (data) {
```
Log is also accumulated in the Ringbuffer object, if user choose to pass in during auditlogger construction time.
-
-
-
-
-
View
@@ -50,7 +50,7 @@ lot of functionality, such as templating and rendering, to support that.
Restify does not.
Restify exists to let you build "strict" API
-services that are maintanable and observable. Restify comes with automatic
+services that are maintainable and observable. Restify comes with automatic
[DTrace](http://en.wikipedia.org/wiki/DTrace) support for all your
handlers, if you're running on a platform that supports DTrace.
@@ -72,6 +72,8 @@
var restify = require('../../lib');
var Logger = require('bunyan');
+var plugins = require('restify-plugins');
+
///--- Globals
@@ -91,7 +93,7 @@ var server = restify.createServer({
name: NAME,
Logger: log,
formatters: {
- 'application/foo': function (req, res, body, cb) {
+ 'application/foo': function (req, res, body) {
if (body instanceof Error) {
body = body.stack;
} else if (Buffer.isBuffer(body)) {
@@ -116,16 +118,16 @@ var server = restify.createServer({
}
}
- return cb(null, body);
+ return body;
}
}
});
-server.use(restify.acceptParser(server.acceptable));
-server.use(restify.authorizationParser());
-server.use(restify.dateParser());
-server.use(restify.queryParser());
-server.use(restify.urlEncodedBodyParser());
+server.use(plugins.acceptParser(server.acceptable));
+server.use(plugins.authorizationParser());
+server.use(plugins.dateParser());
+server.use(plugins.queryParser());
+server.use(plugins.urlEncodedBodyParser());
server.use(function slowHandler(req, res, next) {
setTimeout(function () {
@@ -8,7 +8,7 @@ var util = require('util');
var assert = require('assert-plus');
var bunyan = require('bunyan');
var LRU = require('lru-cache');
-var uuid = require('node-uuid');
+var uuid = require('uuid');
///--- Globals
View
@@ -9,7 +9,7 @@ var sprintf = require('util').format;
var assert = require('assert-plus');
var mime = require('mime');
var Negotatior = require('negotiator');
-var uuid = require('node-uuid');
+var uuid = require('uuid');
var dtrace = require('./dtrace');
View
@@ -349,12 +349,14 @@ Router.prototype.unmount = function unmount(name) {
return (r.name !== route.name);
});
- this.reverse[route.path.source] = reverse.filter(function (r) {
- return (r !== route.method);
- });
+ if (!this.findByPath(route.spec.path, { method: route.method })) {
+ this.reverse[route.path.source] = reverse.filter(function (r) {
+ return (r !== route.method);
+ });
- if (this.reverse[route.path.source].length === 0) {
- delete this.reverse[route.path.source];
+ if (this.reverse[route.path.source].length === 0) {
+ delete this.reverse[route.path.source];
+ }
}
delete this.mounts[name];
@@ -577,6 +579,39 @@ Router.prototype.find = function find(req, res, callback) {
));
};
+/**
+ * Find a route by path. Scans the route list for a route with the same RegEx.
+ * i.e. /foo/:param1/:param2 would match an existing route with different
+ * parameter names /foo/:id/:name since the compiled RegExs match.
+ * @public
+ * @function findByPath
+ * @param {String | RegExp} path a path to find a route for.
+ * @param {Object} options an options object
+ * @returns {Object} returns the route if a match is found
+ */
+Router.prototype.findByPath = function findByPath(path, options) {
+ assert.string(path, 'path');
+ assert.object(options, 'options');
+ assert.string(options.method, 'options.method');
+
+ var route;
+ var routes = this.routes[options.method] || [];
+ var routeRegex = compileURL({
+ url: path,
+ flags: options.flags,
+ urlParamPattern: options.urlParamPattern,
+ strict: this.strict
+ });
+
+ for (var i = 0; i < routes.length; i++) {
+ if (routeRegex.toString() === routes[i].path.toString()) {
+ route = routes[i];
+ break;
+ }
+ }
+ return (route);
+};
+
/**
* toString() serialization.
View
@@ -14,7 +14,7 @@ var mime = require('mime');
var once = require('once');
var semver = require('semver');
var spdy = require('spdy');
-var uuid = require('node-uuid');
+var uuid = require('uuid');
var vasync = require('vasync');
var dtrace = require('./dtrace');
@@ -554,7 +554,7 @@ Server.prototype.param = function param(name, fn) {
/**
* Piggy-backs on the `server.use` method. It attaches a new middleware
- * function that only fires if the specified version matchtes the request.
+ * function that only fires if the specified version matches the request.
*
* Note that if the client does not request a specific version, the middleware
* function always fires. If you don't want this set a default version with a
View
@@ -44,7 +44,7 @@
"name": "restify",
"homepage": "http://restifyjs.com",
"description": "REST framework",
- "version": "4.0.3",
+ "version": "5.0.0-beta-2",
"repository": {
"type": "git",
"url": "git://github.com/restify/node-restify.git"
@@ -64,16 +64,16 @@
"bunyan": "^1.8.1",
"csv": "^1.1.0",
"escape-regexp-component": "^1.0.2",
- "formidable": "^1.0.14",
+ "formidable": "^1.0.17",
"lru-cache": "^4.0.1",
"mime": "^1.2.11",
"negotiator": "^0.6.1",
- "node-uuid": "^1.4.7",
"once": "^1.3.0",
- "qs": "^5.2.0",
+ "qs": "^6.2.1",
"restify-errors": "^4.2.3",
"semver": "^5.0.1",
"spdy": "^3.3.3",
+ "uuid": "^3.0.0",
"vasync": "^1.6.4"
},
"optionalDependencies": {
@@ -87,7 +87,7 @@
"nodeunit": "^0.9.1",
"nsp": "^2.2.0",
"restify-clients": "^1.2.1",
- "restify-plugins": "^1.0.2",
+ "restify-plugins": "^1.0.3",
"validator": "^5.2.0",
"watershed": "^0.3.0"
},
View
@@ -220,3 +220,25 @@ test('Default non-strict routing ignores trailing slash(es)', function (t) {
t.end();
});
+
+test('Find existing route with path', function (t) {
+ var server = restify.createServer();
+ function noop () {}
+
+ var routePath = '/route/:withParam';
+ server.get(routePath, noop);
+
+ var foundRoute = server.router.findByPath(
+ '/route/:withADifferentParamName',
+ { method: 'GET' }
+ );
+ t.equal(foundRoute.spec.path, routePath);
+
+ var notFoundRoute = server.router.findByPath(
+ '/route/:withADifferentParamName([A-Z]{2,3})',
+ { method: 'GET' }
+ );
+ t.notOk(notFoundRoute);
+
+ t.end();
+});
Oops, something went wrong.

0 comments on commit 4e9c327

Please sign in to comment.