Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nohost/router

Package Overview
Dependencies
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nohost/router - npm Package Compare versions

Comparing version 0.6.0 to 0.6.1

2

lib/index.js

@@ -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)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc