@dynacom/core
Advanced tools
Comparing version 1.0.10 to 1.0.11
@@ -7,3 +7,11 @@ const urlPattern = require('url-pattern'); | ||
module.exports = class { | ||
constructor(pattern, handler) { | ||
constructor(pattern, port, handler) { | ||
if (null == handler && 'function' == typeof port) { | ||
handler = port; | ||
port = null; | ||
} else if (Array.isArray(port)) { | ||
this.port = port; | ||
} else if (null != port) { | ||
this.port = [port]; | ||
} | ||
this.textPattern = pattern; | ||
@@ -10,0 +18,0 @@ this.pattern = new urlPattern(pattern); |
@@ -10,3 +10,4 @@ const URL = require('url'); | ||
this.index = { domain: null, route: null } | ||
this.host = this._request.headers.host; | ||
this.address = this._request.headers.host.split(':')[0]; | ||
this.port = this._request.socket.localPort; | ||
this.url = URL.parse(this._request.url, true); | ||
@@ -13,0 +14,0 @@ this.querystring = request.url.query; |
@@ -5,11 +5,14 @@ const urlPattern = require('url-pattern'); | ||
constructor(pattern, method, handler) { | ||
this.textPattern = pattern; | ||
this.pattern = new urlPattern(pattern); | ||
if (Array.isArray(method)) { | ||
if (null == handler && 'function' == typeof method) { | ||
handler = method; | ||
method = null; | ||
} else if (Array.isArray(method)) { | ||
this.method = method; | ||
} else { | ||
} else if (null != method) { | ||
this.method = [method]; | ||
} | ||
this.textPattern = pattern; | ||
this.pattern = new urlPattern(pattern); | ||
this.handler = handler; | ||
} | ||
} |
@@ -47,11 +47,13 @@ const fs = require('fs'); | ||
findDomain(request, domainString, domainIndex = 0) { | ||
findDomain(request, domainString, port, domainIndex = 0) { | ||
let index = null; | ||
let pattern = null; | ||
while (domainIndex < this.domains.length) { | ||
let domainPattern = null; | ||
if (domainPattern = this.domains[domainIndex].pattern.match(domainString)) { | ||
index = domainIndex; | ||
pattern = domainPattern; | ||
break; | ||
if (null == this.domains[domainIndex].port || this.domains[domainIndex].port.includes(port)) { | ||
let domainPattern = null; | ||
if (domainPattern = this.domains[domainIndex].pattern.match(domainString)) { | ||
index = domainIndex; | ||
pattern = domainPattern; | ||
break; | ||
} | ||
} | ||
@@ -68,3 +70,3 @@ domainIndex++; | ||
while (routeIndex < request.domain.routes.length) { | ||
if (request.domain.routes[routeIndex].method.includes(method)) { | ||
if (null == request.domain.routes[routeIndex].method || request.domain.routes[routeIndex].method.includes(method)) { | ||
let routePattern = null; | ||
@@ -87,3 +89,3 @@ if (routePattern = request.domain.routes[routeIndex].pattern.match(routeString)) { | ||
this.findDomain(request, request.host) | ||
this.findDomain(request, request.address, request.port) | ||
this.findRoute(request, request.url.path, request.method); | ||
@@ -118,3 +120,3 @@ | ||
if (Cluster.isMaster) { | ||
for (let threadIndex = 1; threadIndex < this.Config.threads; threadIndex += 1) { | ||
for (let threadIndex = 0; threadIndex < this.Config.threads; threadIndex += 1) { | ||
console.log(this.Config.name + ': starting worker thread #' + threadIndex); | ||
@@ -121,0 +123,0 @@ Cluster.fork(); |
@@ -9,3 +9,3 @@ { | ||
"name": "@dynacom/core", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"repository": { | ||
@@ -12,0 +12,0 @@ "type": "git", |
15790
328