Comparing version 0.15.1 to 0.15.2
@@ -11,4 +11,4 @@ <h1 align="center">Fastify</h1> | ||
* `url`: the path of the url to match this route. | ||
* `schema`: an object containing the schemas for the request and response. | ||
* `url`: the path of the url to match this route (alias: `path`). | ||
* `schema`: an object containing the schemas for the request and response. | ||
They need to be in | ||
@@ -64,3 +64,3 @@ [JSON Schema](http://json-schema.org/) format, check [here](https://github.com/fastify/fastify/blob/master/docs/Validation-And-Serialize.md) for more info. | ||
### Shorthand declaration | ||
The above route declaration is more *Hapi*-like, but if you prefer an *Express/Restify* approach, we support it as well: | ||
The above route declaration is more *Hapi*-like, but if you prefer an *Express/Restify* approach, we support it as well: | ||
`fastify.get(path, [schema], handler)` | ||
@@ -67,0 +67,0 @@ `fastify.head(path, [schema], handler)` |
@@ -254,12 +254,13 @@ 'use strict' | ||
if (map.has(opts.url)) { | ||
if (map.get(opts.url)[opts.method]) { | ||
const url = opts.url || opts.path | ||
if (map.has(url)) { | ||
if (map.get(url)[opts.method]) { | ||
throw new Error(`${opts.method} already set for ${opts.url}`) | ||
} | ||
map.get(opts.url)[opts.method] = opts | ||
map.get(url)[opts.method] = opts | ||
} else { | ||
const node = buildNode(opts.url, router) | ||
const node = buildNode(url, router) | ||
node[opts.method] = opts | ||
map.set(opts.url, node) | ||
map.set(url, node) | ||
} | ||
@@ -266,0 +267,0 @@ |
{ | ||
"name": "fastify", | ||
"version": "0.15.1", | ||
"version": "0.15.2", | ||
"description": "Fast and low overhead web framework, for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "fastify.js", |
@@ -78,1 +78,28 @@ 'use strict' | ||
}) | ||
test('path can be specified in place of uri', t => { | ||
t.plan(3) | ||
fastify.listen(0, function (err) { | ||
if (err) t.error(err) | ||
fastify.server.unref() | ||
fastify.route({ | ||
method: 'GET', | ||
path: '/path', | ||
handler: function (req, reply) { | ||
reply.send({ hello: 'world' }) | ||
} | ||
}) | ||
const reqOpts = { | ||
method: 'GET', | ||
uri: 'http://localhost:' + fastify.server.address().port + '/path' | ||
} | ||
request(reqOpts, (err, response, body) => { | ||
t.error(err) | ||
t.strictEqual(response.statusCode, 200) | ||
t.deepEqual(JSON.parse(body), { hello: 'world' }) | ||
}) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
156493
76
4208