From e8328594b9202b16e6851b4c5cb92e7ae27b81a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Hal=C3=A1sz?= Date: Mon, 13 Jun 2016 22:10:52 -0700 Subject: [PATCH] v0.10.8 + New Utils Controller + Moved isset() into the Util Controller --- Changelog.md | 2 ++ controllers/listen.js | 4 ++-- controllers/protocols/http/host.js | 3 ++- controllers/protocols/http/signal.js | 9 +++++---- controllers/utils.js | 3 +++ 5 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 controllers/utils.js diff --git a/Changelog.md b/Changelog.md index 9417119..6620e0b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,7 @@ ## v0.10.8 ** - 2016 June 13 - Upgrade `diet-qs` with the new `querystrings` module that fixes nested Query String to Array conversions. +- New Utils Controller +- Moved isset() into the Util Controller ## v0.10.6 ** - 2016 May 10 - Ports are now wildcards for every hostname. Listening on a Port (`app.listen(8000)`) will accept any Hostname request within that Port. Listening on a Hostname (`app2.listen('http://test.com:8000/')`) within that Port will have priority. diff --git a/controllers/listen.js b/controllers/listen.js index 2a2ad3d..224fa93 100644 --- a/controllers/listen.js +++ b/controllers/listen.js @@ -10,7 +10,7 @@ const url = require('url') const parent = module.parent.exports - + const utils = require('./utils') // =========================================================================== // Exports // =========================================================================== @@ -33,7 +33,7 @@ } else if(typeof location == 'object') { app.location = location; - } else if(!isset(location)){ + } else if(!utils.isset(location)){ app.location = url.parse(protocolName+'://0.0.0.0:80/'); } diff --git a/controllers/protocols/http/host.js b/controllers/protocols/http/host.js index f70c0f5..38cdb13 100644 --- a/controllers/protocols/http/host.js +++ b/controllers/protocols/http/host.js @@ -11,6 +11,7 @@ const Error = require('../../error') const url = require('url') const RouteIterator = require('../../iterator') + const utils = require('../../utils') // =========================================================================== // Exports @@ -30,7 +31,7 @@ var host = request.headers.host ? request.headers.host : '' ; var location = request.url ? url.parse(request.url) : '' ; var port = host.split(':')[1] || protocol.globalAgent.defaultPort; - var hostname = isset(port) ? host : host + ':' + protocol.globalAgent.defaultPort ; + var hostname = utils.isset(port) ? host : host + ':' + protocol.globalAgent.defaultPort ; // get app (host controller) handling this hostname var app = App.hosts[hostname] || App.hosts[hostname+':'+port] || App.hosts['0.0.0.0:'+port] diff --git a/controllers/protocols/http/signal.js b/controllers/protocols/http/signal.js index 4ab92cd..17cb1b2 100644 --- a/controllers/protocols/http/signal.js +++ b/controllers/protocols/http/signal.js @@ -8,10 +8,11 @@ // Dependencies // =========================================================================== - const qs = require('diet-qs') + const qs = require('querystrings') const fs = require('fs') const url = require('url') const status_codes = require('http').STATUS_CODES; + const utils = require('../../utils') // =========================================================================== // Exports @@ -111,7 +112,7 @@ if(!signal.statusCode) signal.status(200) signal.header('content-type', 'application/json') var data = signal.data - if(isset(input)) data = Object.merge(signal.data, input) + if(utils.isset(input)) data = Object.merge(signal.data, input) data.passed = true signal.end(data, isLast) }, @@ -119,11 +120,11 @@ if(!signal.statusCode) signal.status(200) signal.header('content-type', 'application/json') if(signal.data.errors) signal.errors = Object.merge(signal.error, signal.data.errors) - if(isset(input)) data = Object.merge(signal.errors, input) + if(utils.isset(input)) data = Object.merge(signal.errors, input) signal.end({ passed: false, errors: signal.errors }, isLast) }, jsonString: function(input){ - if(isset(input)) signal.data = Object.merge(signal.data, input) + if(utils.isset(input)) signal.data = Object.merge(signal.data, input) if(!signal.statusCode) signal.status(200) signal.header('content-type', 'application/json') return JSON.stringify(signal.data); diff --git a/controllers/utils.js b/controllers/utils.js new file mode 100644 index 0000000..dbe5f8d --- /dev/null +++ b/controllers/utils.js @@ -0,0 +1,3 @@ +module.exports.isset = function isset(object){ + return (object != "undefined" && object != undefined && object != null && object != "" && typeof(object) != 'undefined') ? true : false ; +} \ No newline at end of file