@nohost/router
Advanced tools
Comparing version 0.6.0 to 0.6.1
@@ -135,3 +135,3 @@ const url = require('url'); | ||
const status = await this._getStatus(space, group, name); | ||
if (!status.host) { | ||
if (!status || !status.host) { | ||
return this._connectDefault(req, res, callback); | ||
@@ -138,0 +138,0 @@ } |
@@ -6,2 +6,4 @@ const http = require('http'); | ||
const TIMEOUT = 2000; | ||
let curServers; | ||
const noop = (_) => _; | ||
@@ -87,4 +89,3 @@ const getBody = (url) => { | ||
const usableServers = []; | ||
const list = []; | ||
await Promise.all(servers.map(async (server) => { | ||
let list = await Promise.all(servers.map(async (server) => { | ||
const workerNum = await getWorkerNum(server); | ||
@@ -94,37 +95,14 @@ if (workerNum) { | ||
usableServers.push(server); | ||
list.push(`${server.host}:${server.port}/${workerNum}`); | ||
return `${server.host}:${server.port}/${workerNum}`; | ||
} | ||
})); | ||
return list.length && { | ||
list = list.filter(noop); | ||
if (!list.length) { | ||
return curServers; | ||
} | ||
curServers = { | ||
servers: usableServers, | ||
base64: Buffer.from(list.join()).toString('base64'), | ||
}; | ||
return curServers; | ||
}; | ||
exports.getWorkers = async (servers) => { | ||
servers = parseServers(servers); | ||
if (!servers.length) { | ||
return servers; | ||
} | ||
const workers = []; | ||
const usableServers = []; | ||
const base64 = []; | ||
await Promise.all(servers.map(async (server) => { | ||
const workerNum = await getWorkerNum(server); | ||
if (workerNum) { | ||
server.workerNum = workerNum; | ||
const { host, port } = server; | ||
const option = { host, port }; | ||
usableServers.push(option); | ||
base64.push(`${host}:${port}/${workerNum}`); | ||
for (let i = 0; i < workerNum; i++) { | ||
workers.push(option); | ||
} | ||
} | ||
})); | ||
usableServers._base64 = Buffer.from(base64.join()).toString('base64'); | ||
workers.totalLen = workers.length; | ||
usableServers.totalLen = usableServers.length; | ||
workers._servers = usableServers; | ||
return workers; | ||
}; |
{ | ||
"name": "@nohost/router", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "Nohost cluster router", | ||
@@ -5,0 +5,0 @@ "main": "lib/", |
@@ -94,3 +94,16 @@ # router | ||
### 只转发到指定 Nohost 服务 | ||
``` js | ||
const Router = require('@nohost/router'); | ||
const router = new Router({ | ||
host: '10.x.x.x', | ||
port: 8080, | ||
}); | ||
router.proxy(req, res); // 同测试用例,无需设置 space / group,env 按需设置 | ||
router.proxyUI(req, res); // 同测试用例,无需设置 space / group,env 按需设置 | ||
``` | ||
具体实现参考:[测试用例](./test/README.md) | ||
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
109
1
13587
325