Comparing version 1.0.0-alpha-05 to 1.0.0-alpha-06
@@ -39,3 +39,4 @@ 'use strict'; | ||
* url: '/forward', | ||
* route: 'app/Forward' | ||
* route: 'app/Forward', | ||
* dataEvent: true | ||
* }, | ||
@@ -42,0 +43,0 @@ * { |
@@ -715,16 +715,27 @@ 'use strict'; | ||
this.response.once('close', () => this.destroy()); | ||
// push data | ||
this.request.on('data', item => this.data.push(item)); | ||
} | ||
// on data end process request | ||
let request = this.isForwarded ? Promise.resolve(true) : new Promise(resolve => this.request.on('end', resolve)); | ||
return request | ||
.then(() => { | ||
return router.parseRequest(this.getPathname(), this.getMethod(), this.getRequestHeaders()) | ||
.then(result => { | ||
if (result.dataEvent && !this.isForwarded) { | ||
logger.info('Route.parseRequest.withDataEvent', { | ||
id: this.id, | ||
isCustomError: this.isCustomError, | ||
isForwarded: this.isForwarded, | ||
path: this.getPathname(), | ||
method: this.getMethod(), | ||
result: result | ||
}); | ||
this.request.on('data', item => this.data.push(item)); | ||
return new Promise(resolve => this.request.on('end', resolve.bind({}, result))); | ||
} | ||
logger.info('Route.parseRequest', { | ||
id: this.id, | ||
isCustomError: this.isCustomError, | ||
isForwarded: this.isForwarded, | ||
path: this.getPathname(), | ||
method: this.getMethod() | ||
method: this.getMethod(), | ||
result: result | ||
}); | ||
return router.parseRequest(this.getPathname(), this.getMethod(), this.getRequestHeaders()); | ||
return result; | ||
}) | ||
@@ -731,0 +742,0 @@ .then(result => { |
@@ -17,10 +17,19 @@ 'use strict'; | ||
* @param {Object} config | ||
* @param {Object} types to extend route rule on inherit while implementing custom parseRequest and createUrl | ||
* @param {Object} types extend route rule on inherit while implementing custom parseRequest and createUrl | ||
* @constructor | ||
* @description | ||
* Route rule is used to add route definitions to router | ||
* Route rule is used to add route definitions to router. | ||
* To enable data event dataEvent property has to be passed to router as dataEvent: true | ||
* @example | ||
* class DynamicRule extends RouteRule { | ||
* parseRequest() { | ||
* | ||
* parseRequest(pathname, method) { | ||
* let query = {}; | ||
* let route = 'user/contact'; | ||
* return { | ||
pathname, | ||
method, | ||
query, | ||
dataEvent: true, | ||
route | ||
} | ||
* } | ||
@@ -39,3 +48,4 @@ * createUrl() { | ||
* url: '/', | ||
* route: 'app/Index' | ||
* route: 'app/Index', | ||
* dataEvent: true | ||
* }, | ||
@@ -57,3 +67,4 @@ * { | ||
methods: Type.ARRAY, | ||
bootstrap: Type.OBJECT | ||
bootstrap: Type.OBJECT, | ||
dataEvent: Type.BOOLEAN | ||
}, types)); | ||
@@ -66,2 +77,4 @@ | ||
this.methods = ['GET']; | ||
this.dataEvent = config.dataEvent || false; | ||
if (Type.isArray(config.methods) && !config.methods.every(item => this.validMethods.indexOf(item) > -1)) { | ||
@@ -95,2 +108,3 @@ throw new error.HttpError(500, `RouteRule: rule must contain valid methods`, { | ||
* @param {String} url | ||
* @private | ||
* | ||
@@ -234,3 +248,15 @@ * @description | ||
* @description | ||
* Parse request and get result | ||
* Parse request and get result when route rule is extend following object structure has to be returned. | ||
* @return {Object} | ||
* | ||
* @example | ||
* parseRequest(pathname, method) { | ||
* return { | ||
* pathname, | ||
* method, | ||
* query, | ||
* dataEvent: true, | ||
* route | ||
* } | ||
* } | ||
*/ | ||
@@ -264,2 +290,3 @@ parseRequest(pathname, method) { | ||
query, | ||
dataEvent: this.dataEvent, | ||
route: this.route | ||
@@ -266,0 +293,0 @@ }; |
@@ -5,3 +5,3 @@ { | ||
"description": "Lightweight application framework with dyependency injection and dynamic type checking for node js", | ||
"version": "1.0.0-alpha-05", | ||
"version": "1.0.0-alpha-06", | ||
"dependencies": { | ||
@@ -8,0 +8,0 @@ "di-node": "0.2.x", |
@@ -1,2 +0,2 @@ | ||
# Appix 1.0.0-alpha-03 [](https://travis-ci.org/igorzg/appix) | ||
# Appix 1.0.0-alpha-06 [](https://travis-ci.org/igorzg/appix) | ||
* Es6 Node.js framework dev version | ||
@@ -3,0 +3,0 @@ * Lightweight application framework with dyependency injection and dynamic type checking for node js |
89417
2977