mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-20 09:28:37 +00:00
make proxy change port if it's already taken
This commit is contained in:
parent
9d3064e3ae
commit
16a13ee705
@ -26,7 +26,7 @@
|
|||||||
},
|
},
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "cross-env BABEL_ENV=node babel src --out-dir dist --root-mode upward --source-maps",
|
"build": "cross-env BABEL_ENV=node babel src --extensions \".ts\",\".js\" --out-dir dist --root-mode upward --source-maps",
|
||||||
"ci": "npm run qa",
|
"ci": "npm run qa",
|
||||||
"clean": "npm run reset",
|
"clean": "npm run reset",
|
||||||
"lint": "npm-run-all lint:*",
|
"lint": "npm-run-all lint:*",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {Embark, Events, Logger} /* supplied by @types/embark in packages/embark-typings */ from "embark";
|
import {Embark, Events, Logger} /* supplied by @types/embark in packages/embark-typings */ from "embark";
|
||||||
import {IPC} from "embark-core";
|
import {IPC} from "embark-core";
|
||||||
import {AccountParser, dappPath} from "embark-utils";
|
import {AccountParser, dappPath, findNextPort} from "embark-utils";
|
||||||
import {Proxy} from "./proxy";
|
import {Proxy} from "./proxy";
|
||||||
|
|
||||||
const constants = require("embark-core/constants");
|
const constants = require("embark-core/constants");
|
||||||
@ -12,8 +12,8 @@ export default class ProxyManager {
|
|||||||
private rpcProxy: any;
|
private rpcProxy: any;
|
||||||
private wsProxy: any;
|
private wsProxy: any;
|
||||||
private readonly host: string;
|
private readonly host: string;
|
||||||
private readonly rpcPort: number;
|
private rpcPort: number | undefined;
|
||||||
private readonly wsPort: number;
|
private wsPort: number | undefined;
|
||||||
private ready: boolean;
|
private ready: boolean;
|
||||||
|
|
||||||
constructor(private embark: Embark, _options: any) {
|
constructor(private embark: Embark, _options: any) {
|
||||||
@ -23,8 +23,6 @@ export default class ProxyManager {
|
|||||||
this.ready = false;
|
this.ready = false;
|
||||||
|
|
||||||
this.host = "localhost";
|
this.host = "localhost";
|
||||||
this.rpcPort = this.embark.config.blockchainConfig.rpcPort + constants.blockchain.servicePortOnProxy;
|
|
||||||
this.wsPort = this.embark.config.blockchainConfig.wsPort + constants.blockchain.servicePortOnProxy;
|
|
||||||
|
|
||||||
this.events.once("blockchain:started", async () => {
|
this.events.once("blockchain:started", async () => {
|
||||||
await this.setupProxy();
|
await this.setupProxy();
|
||||||
@ -37,9 +35,11 @@ export default class ProxyManager {
|
|||||||
if (!this.embark.config.blockchainConfig.proxy) {
|
if (!this.embark.config.blockchainConfig.proxy) {
|
||||||
return cb(null, this.embark.config.blockchainConfig.endpoint);
|
return cb(null, this.embark.config.blockchainConfig.endpoint);
|
||||||
}
|
}
|
||||||
// TODO actually check for the wanted connection
|
// TODO Check if the proxy can support HTTPS, though it probably doesn't matter since it's local
|
||||||
|
if (this.embark.config.blockchainConfig.wsRPC) {
|
||||||
|
return cb(null, `ws://${this.host}:${this.wsPort}`);
|
||||||
|
}
|
||||||
cb(null, `http://${this.host}:${this.rpcPort}`);
|
cb(null, `http://${this.host}:${this.rpcPort}`);
|
||||||
// cb(null, `ws://${this.host}:${this.wsPort}`);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +58,11 @@ export default class ProxyManager {
|
|||||||
if (!this.embark.config.blockchainConfig.proxy) {
|
if (!this.embark.config.blockchainConfig.proxy) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const port = await findNextPort(this.embark.config.blockchainConfig.rpcPort + constants.blockchain.servicePortOnProxy);
|
||||||
|
|
||||||
|
this.rpcPort = port;
|
||||||
|
this.wsPort = port + 1;
|
||||||
|
|
||||||
const addresses = AccountParser.parseAccountsConfig(this.embark.config.blockchainConfig.accounts, false, dappPath(), this.logger);
|
const addresses = AccountParser.parseAccountsConfig(this.embark.config.blockchainConfig.accounts, false, dappPath(), this.logger);
|
||||||
|
|
||||||
[this.rpcProxy, this.wsProxy] = await Promise.all([
|
[this.rpcProxy, this.wsProxy] = await Promise.all([
|
||||||
|
Loading…
x
Reference in New Issue
Block a user