mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-18 08:36:51 +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",
|
||||
"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",
|
||||
"clean": "npm run reset",
|
||||
"lint": "npm-run-all lint:*",
|
||||
|
@ -1,6 +1,6 @@
|
||||
import {Embark, Events, Logger} /* supplied by @types/embark in packages/embark-typings */ from "embark";
|
||||
import {IPC} from "embark-core";
|
||||
import {AccountParser, dappPath} from "embark-utils";
|
||||
import {AccountParser, dappPath, findNextPort} from "embark-utils";
|
||||
import {Proxy} from "./proxy";
|
||||
|
||||
const constants = require("embark-core/constants");
|
||||
@ -12,8 +12,8 @@ export default class ProxyManager {
|
||||
private rpcProxy: any;
|
||||
private wsProxy: any;
|
||||
private readonly host: string;
|
||||
private readonly rpcPort: number;
|
||||
private readonly wsPort: number;
|
||||
private rpcPort: number | undefined;
|
||||
private wsPort: number | undefined;
|
||||
private ready: boolean;
|
||||
|
||||
constructor(private embark: Embark, _options: any) {
|
||||
@ -23,8 +23,6 @@ export default class ProxyManager {
|
||||
this.ready = false;
|
||||
|
||||
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 () => {
|
||||
await this.setupProxy();
|
||||
@ -37,9 +35,11 @@ export default class ProxyManager {
|
||||
if (!this.embark.config.blockchainConfig.proxy) {
|
||||
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, `ws://${this.host}:${this.wsPort}`);
|
||||
});
|
||||
}
|
||||
|
||||
@ -58,6 +58,11 @@ export default class ProxyManager {
|
||||
if (!this.embark.config.blockchainConfig.proxy) {
|
||||
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);
|
||||
|
||||
[this.rpcProxy, this.wsProxy] = await Promise.all([
|
||||
|
Loading…
x
Reference in New Issue
Block a user