Comparing version 2.2.1 to 2.2.2
@@ -12,4 +12,7 @@ function next (middlewares, req, res, index, routerPatterns = {}, defaultRoute, errorHandler) { | ||
function step (err) { | ||
if (err) return errorHandler(err, req, res) | ||
return next(middlewares, req, res, ++index, routerPatterns, defaultRoute, errorHandler) | ||
if (err) { | ||
return errorHandler(err, req, res) | ||
} else { | ||
return next(middlewares, req, res, ++index, routerPatterns, defaultRoute, errorHandler) | ||
} | ||
} | ||
@@ -23,2 +26,4 @@ | ||
req.preRouterUrl = req.url | ||
req.preRouterPath = req.path | ||
req.url = req.url.replace(pattern, '') | ||
@@ -31,3 +36,3 @@ } | ||
} catch (err) { | ||
errorHandler(err, req, res) | ||
return errorHandler(err, req, res) | ||
} | ||
@@ -34,0 +39,0 @@ } |
@@ -62,3 +62,6 @@ const Trouter = require('trouter') | ||
req.url = req.preRouterUrl | ||
req.path = req.preRouterPath | ||
delete req.preRouterUrl | ||
delete req.preRouterPath | ||
@@ -65,0 +68,0 @@ step() |
@@ -74,3 +74,3 @@ const uWS = require('uWebSockets.js') | ||
this.req = uRequest | ||
this.url = uRequest.getUrl() | ||
this.url = uRequest.getUrl() + (uRequest.getQuery() ? '?' + uRequest.getQuery() : '') | ||
this.method = uRequest.getMethod().toUpperCase() | ||
@@ -83,4 +83,2 @@ this.body = null | ||
}) | ||
this.query = uRequest.getQuery() | ||
} | ||
@@ -87,0 +85,0 @@ |
{ | ||
"name": "0http", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"description": "Cero friction HTTP request router. The need for speed!", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,12 +18,4 @@ /* global describe, it */ | ||
}) | ||
const router2 = require('../lib/router/sequential')() | ||
router2.get('/url', (req, res, next) => { | ||
req.body = req.url | ||
next() | ||
}) | ||
router.use('/r2', router2) | ||
router.use('/r1', router1) | ||
router.use('/*', (req, res, next) => { | ||
router.use('/r1', (req, res, next) => { | ||
res.end(req.url + ':' + req.body) | ||
@@ -34,2 +26,9 @@ | ||
const router2 = require('../lib/router/sequential')() | ||
router2.get('/url/:age', (req, res, next) => { | ||
req.params.age = ~~req.params.age | ||
res.end(JSON.stringify(req.params)) | ||
}) | ||
router.use('/r2/:name', router2) | ||
server.listen(~~process.env.PORT, err => { | ||
@@ -49,3 +48,3 @@ if (!err) done() | ||
it('should hit GET /url on nested routers', async () => { | ||
it('should hit GET /url on nested router /r1', async () => { | ||
await request(baseUrl) | ||
@@ -57,8 +56,13 @@ .get('/r1/url') | ||
}) | ||
}) | ||
it('should hit GET /url/:age on nested router /r2/:name', async () => { | ||
await request(baseUrl) | ||
.get('/r2/url?var=value') | ||
.get('/r2/rolando/url/33?var=value') | ||
.expect(200) | ||
.then((response) => { | ||
expect(response.text).to.equal('/r2/url?var=value:/url?var=value') | ||
expect(JSON.parse(response.text)).to.deep.include({ | ||
name: 'rolando', | ||
age: 33 | ||
}) | ||
}) | ||
@@ -65,0 +69,0 @@ }) |
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
24046
587
23