mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-13 07:36:21 +00:00
fix most rebase issues
This commit is contained in:
parent
538b19ff19
commit
d09077ea0a
@ -34,8 +34,8 @@ class ProcessLauncher {
|
||||
_subscribeToMessages() {
|
||||
const self = this;
|
||||
this.process.on('message', (msg) => {
|
||||
if (msg.error) {
|
||||
self.logger.error(msg.error);
|
||||
if (msg.error) {
|
||||
self.logger.error(msg.error);
|
||||
}
|
||||
if (msg.result === constants.process.log) {
|
||||
return self._handleLog(msg);
|
||||
@ -81,7 +81,13 @@ class ProcessLauncher {
|
||||
_handleLog(msg) {
|
||||
const timestamp = new Date().getTime();
|
||||
this.events.emit('process-log-' + this.name, msg.type, msg.message, this.name, timestamp);
|
||||
this.logs.push({msg: msg.message, msg_clear: msg.message.stripColors, logLevel: msg.logLevel, name: this.name, timestamp});
|
||||
this.logs.push({
|
||||
msg: msg.message,
|
||||
msg_clear: msg.message.stripColors,
|
||||
logLevel: msg.logLevel,
|
||||
name: this.name,
|
||||
timestamp
|
||||
});
|
||||
if (this.silent && msg.type !== 'error') {
|
||||
return;
|
||||
}
|
||||
@ -191,7 +197,7 @@ class ProcessLauncher {
|
||||
* Unsubscribes from a previously subscribed key-value pair (or key if no value)
|
||||
* @param {String} key Message key to unsubscribe
|
||||
* @param {String} value [Optional] Value of the key to unsubscribe
|
||||
* If there is no value, unsubscribes from all the values of that key
|
||||
* If there is no value, unsubscribes from all the values of that key
|
||||
* @return {void}
|
||||
*/
|
||||
unsubscribeTo(key, value) {
|
||||
|
@ -43,13 +43,13 @@ class BlockchainConnector {
|
||||
this.subscribeToPendingTransactions();
|
||||
}
|
||||
|
||||
initWeb3(cb) {
|
||||
if (!cb) {
|
||||
cb = function(){};
|
||||
}
|
||||
if (this.isWeb3Ready) {
|
||||
this.events.emit(WEB3_READY);
|
||||
return cb();
|
||||
initWeb3(cb) {
|
||||
if (!cb) {
|
||||
cb = function() {};
|
||||
}
|
||||
if (this.isWeb3Ready) {
|
||||
this.events.emit(WEB3_READY);
|
||||
return cb();
|
||||
}
|
||||
|
||||
const self = this;
|
||||
@ -84,7 +84,10 @@ class BlockchainConnector {
|
||||
networkId = constants.blockchain.networkIds[self.blockchainConfig.networkType];
|
||||
}
|
||||
if (id.toString() !== networkId.toString()) {
|
||||
self.logger.warn(__('Connected to a blockchain node on network {{realId}} while your config specifies {{configId}}', {realId: id, configId: networkId}));
|
||||
self.logger.warn(__('Connected to a blockchain node on network {{realId}} while your config specifies {{configId}}', {
|
||||
realId: id,
|
||||
configId: networkId
|
||||
}));
|
||||
self.logger.warn(__('Make sure you started the right blockchain node'));
|
||||
}
|
||||
})
|
||||
@ -129,7 +132,7 @@ class BlockchainConnector {
|
||||
const self = this;
|
||||
const NO_NODE = 'noNode';
|
||||
|
||||
this.events.request("services:register", 'Ethereum', function (cb) {
|
||||
this.events.request("services:register", 'Ethereum', function(cb) {
|
||||
async.waterfall([
|
||||
function checkNodeConnection(next) {
|
||||
if (!self.web3.currentProvider) {
|
||||
@ -227,7 +230,7 @@ class BlockchainConnector {
|
||||
'/embark-api/blockchain/blocks/:blockNumber',
|
||||
(req, res) => {
|
||||
self.getBlock(req.params.blockNumber, (err, block) => {
|
||||
if(err){
|
||||
if (err) {
|
||||
self.logger.error(err);
|
||||
}
|
||||
res.send(block);
|
||||
@ -250,7 +253,7 @@ class BlockchainConnector {
|
||||
'/embark-api/blockchain/transactions/:hash',
|
||||
(req, res) => {
|
||||
self.getTransaction(req.params.hash, (err, transaction) => {
|
||||
if(err){
|
||||
if (err) {
|
||||
self.logger.error(err);
|
||||
}
|
||||
res.send(transaction);
|
||||
@ -298,11 +301,11 @@ class BlockchainConnector {
|
||||
callback(null, account);
|
||||
});
|
||||
}
|
||||
], function(_err, account){
|
||||
], function(_err, account) {
|
||||
accounts.push(account);
|
||||
eachCb();
|
||||
});
|
||||
}, function () {
|
||||
}, function() {
|
||||
callback(accounts);
|
||||
});
|
||||
});
|
||||
@ -314,7 +317,7 @@ class BlockchainConnector {
|
||||
function(next) {
|
||||
self.getAccountsWithTransactionCount((accounts) => {
|
||||
let account = accounts.find((a) => a.address === address);
|
||||
if(!account) {
|
||||
if (!account) {
|
||||
return next("No account found with this address");
|
||||
}
|
||||
next(null, account);
|
||||
@ -336,7 +339,7 @@ class BlockchainConnector {
|
||||
next(null, account);
|
||||
});
|
||||
}
|
||||
], function (err, result) {
|
||||
], function(err, result) {
|
||||
if (err) {
|
||||
callback();
|
||||
}
|
||||
@ -372,7 +375,7 @@ class BlockchainConnector {
|
||||
function(next) {
|
||||
async.times(limit, function(n, eachCb) {
|
||||
self.web3.eth.getBlock(from - n, returnTransactionObjects, function(err, block) {
|
||||
if (err){
|
||||
if (err) {
|
||||
self.logger.error(err);
|
||||
return eachCb();
|
||||
}
|
||||
@ -381,7 +384,7 @@ class BlockchainConnector {
|
||||
});
|
||||
}, next);
|
||||
}
|
||||
], function () {
|
||||
], function() {
|
||||
callback(blocks);
|
||||
});
|
||||
}
|
||||
@ -456,60 +459,14 @@ class BlockchainConnector {
|
||||
}
|
||||
|
||||
deployContractFromObject(deployContractObject, params, cb) {
|
||||
const self = this;
|
||||
let hash;
|
||||
let calledBacked = false;
|
||||
|
||||
function callback(err, receipt) {
|
||||
if (calledBacked) {
|
||||
return;
|
||||
}
|
||||
if (!err && !receipt.contractAddress) {
|
||||
return; // Not deployed yet. Need to wait
|
||||
}
|
||||
if (interval) {
|
||||
clearInterval(interval);
|
||||
}
|
||||
calledBacked = true;
|
||||
cb(err, receipt);
|
||||
}
|
||||
|
||||
// This interval is there to compensate for the event that sometimes doesn't get triggered when using WebSocket
|
||||
// FIXME The issue somehow only happens when the blockchain node is started in the same terminal
|
||||
const interval = setInterval(() => {
|
||||
if (!hash) {
|
||||
return; // Wait until we receive the hash
|
||||
}
|
||||
self.web3.eth.getTransactionReceipt(hash, (err, receipt) => {
|
||||
if (!err && !receipt) {
|
||||
return; // Transaction is not yet complete
|
||||
}
|
||||
callback(err, receipt);
|
||||
});
|
||||
}, 500);
|
||||
|
||||
deployContractObject.send({
|
||||
embarkJsUtils.secureSend(this.web3, deployContractObject, {
|
||||
from: params.from, gas: params.gas, gasPrice: params.gasPrice
|
||||
}, function (err, transactionHash) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
hash = transactionHash;
|
||||
}).on('receipt', function (receipt) {
|
||||
if (receipt.contractAddress !== undefined) {
|
||||
callback(null, receipt);
|
||||
}
|
||||
}).then(function (_contract) {
|
||||
if (!hash) {
|
||||
return; // Somehow we didn't get the receipt yet... Interval will catch it
|
||||
}
|
||||
self.web3.eth.getTransactionReceipt(hash, callback);
|
||||
}).catch(callback);
|
||||
}, true, cb);
|
||||
}
|
||||
|
||||
determineDefaultAccount(cb) {
|
||||
const self = this;
|
||||
self.getAccounts(function (err, accounts) {
|
||||
self.getAccounts(function(err, accounts) {
|
||||
if (err) {
|
||||
self.logger.error(err);
|
||||
return cb(new Error(err));
|
||||
@ -526,6 +483,20 @@ class BlockchainConnector {
|
||||
// can just be a command without a callback
|
||||
this.events.emit("runcode:register", "web3", this.web3);
|
||||
}
|
||||
|
||||
subscribeToPendingTransactions() {
|
||||
const self = this;
|
||||
this.onReady(() => {
|
||||
if (self.logsSubscription) {
|
||||
self.logsSubscription.unsubscribe();
|
||||
}
|
||||
self.logsSubscription = self.web3.eth
|
||||
.subscribe('newBlockHeaders', () => {})
|
||||
.on("data", function (blockHeader) {
|
||||
self.events.emit('block:header', blockHeader);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BlockchainConnector;
|
||||
|
@ -80,8 +80,7 @@ class ContractsManager {
|
||||
cb(results);
|
||||
});
|
||||
|
||||
let plugin = this.plugins.createPlugin('deployment', {});
|
||||
plugin.registerAPICall(
|
||||
embark.registerAPICall(
|
||||
'get',
|
||||
'/embark-api/contract/:contractName',
|
||||
(req, res) => {
|
||||
@ -89,7 +88,7 @@ class ContractsManager {
|
||||
}
|
||||
);
|
||||
|
||||
plugin.registerAPICall(
|
||||
embark.registerAPICall(
|
||||
'post',
|
||||
'/embark-api/contract/:contractName/function',
|
||||
(req, res) => {
|
||||
@ -125,7 +124,7 @@ class ContractsManager {
|
||||
}
|
||||
);
|
||||
|
||||
plugin.registerAPICall(
|
||||
embark.registerAPICall(
|
||||
'post',
|
||||
'/embark-api/contract/:contractName/deploy',
|
||||
(req, res) => {
|
||||
@ -156,7 +155,7 @@ class ContractsManager {
|
||||
}
|
||||
);
|
||||
|
||||
plugin.registerAPICall(
|
||||
embark.registerAPICall(
|
||||
'get',
|
||||
'/embark-api/contracts',
|
||||
(req, res) => {
|
||||
|
@ -157,18 +157,15 @@ __embarkENS.setProvider = function (config) {
|
||||
self.registration = config.registration;
|
||||
self.env = config.env;
|
||||
|
||||
EmbarkJS.onReady(() => {
|
||||
self.registration = config.registration;
|
||||
|
||||
EmbarkJS.onReady(() => {
|
||||
web3.eth.net.getId()
|
||||
.then((id) => {
|
||||
const registryAddress = self.registryAddresses[id] || config.registryAddress;
|
||||
self.isAvailable = true;
|
||||
self.ens = new EmbarkJS.Contract({abi: config.registryAbi, address: registryAddress});
|
||||
self.registrar = new EmbarkJS.Contract({abi: config.registrarAbi, address: config.registrarAddress});
|
||||
self.resolver = new EmbarkJS.Contract({abi: config.resolverAbi, address: config.resolverAddress});
|
||||
})
|
||||
const registryAddress = self.registryAddresses[id] || config.registryAddress;
|
||||
self.isAvailable = true;
|
||||
self.ens = new EmbarkJS.Contract({abi: config.registryAbi, address: registryAddress});
|
||||
self.registrar = new EmbarkJS.Contract({abi: config.registrarAbi, address: config.registrarAddress});
|
||||
self.resolver = new EmbarkJS.Contract({abi: config.resolverAbi, address: config.resolverAddress});
|
||||
})
|
||||
.catch(err => {
|
||||
if (err.message.indexOf('Provider not set or invalid') > -1) {
|
||||
console.warn(ERROR_MESSAGE);
|
||||
|
@ -3,8 +3,7 @@ const utils = require('../../utils/utils.js');
|
||||
const namehash = require('eth-ens-namehash');
|
||||
const async = require('async');
|
||||
const embarkJsUtils = require('embarkjs').Utils;
|
||||
const reverseAddrSuffix = '.addr.reverse';
|
||||
|
||||
const ENSFunctions = require('./ENSFunctions');
|
||||
const reverseAddrSuffix = '.addr.reverse';
|
||||
|
||||
class ENS {
|
||||
@ -26,7 +25,7 @@ class ENS {
|
||||
|
||||
this.addENSToEmbarkJS();
|
||||
this.configureContracts();
|
||||
this.registerActionForEvents();
|
||||
this.registerEvents();
|
||||
}
|
||||
|
||||
registerEvents() {
|
||||
@ -326,14 +325,6 @@ class ENS {
|
||||
"default": {
|
||||
"gas": "auto"
|
||||
},
|
||||
"development": {
|
||||
"contracts": {
|
||||
"ENS": {
|
||||
"deploy": false,
|
||||
"silent": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"development": {
|
||||
"contracts": {
|
||||
"ENSRegistry": {
|
||||
@ -424,94 +415,6 @@ class ENS {
|
||||
}
|
||||
}
|
||||
|
||||
configureRootRegistrar() {
|
||||
const self = this;
|
||||
let rootNode = namehash.hash(self.registration.rootDomain);
|
||||
self.embark.registerContractConfiguration({
|
||||
"default": {
|
||||
"gas": "auto",
|
||||
"contracts": {
|
||||
"FIFSRegistrar": {
|
||||
"deploy": true,
|
||||
"args": ["$ENSRegistry", rootNode],
|
||||
"onDeploy": [
|
||||
`ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send().then(() => {
|
||||
ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send();
|
||||
var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '.addr.reverse');
|
||||
ENSRegistry.methods.setResolver(reverseNode, "$Resolver").send();
|
||||
Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send();
|
||||
Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send();
|
||||
})`
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"ropsten": {
|
||||
"contracts": {
|
||||
"ENSRegistry": {
|
||||
"address": "0x112234455c3a32fd11230c42e7bccd4a84e02010"
|
||||
},
|
||||
"Resolver": {
|
||||
"deploy": false
|
||||
},
|
||||
"FIFSRegistrar": {
|
||||
"deploy": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"rinkeby": {
|
||||
"contracts": {
|
||||
"ENSRegistry": {
|
||||
"address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A"
|
||||
},
|
||||
"Resolver": {
|
||||
"deploy": false
|
||||
},
|
||||
"FIFSRegistrar": {
|
||||
"deploy": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"livenet": {
|
||||
"contracts": {
|
||||
"ENSRegistry": {
|
||||
"address": "0x314159265dd8dbb310642f98f50c066173c1259b"
|
||||
},
|
||||
"Resolver": {
|
||||
"deploy": false
|
||||
},
|
||||
"FIFSRegistrar": {
|
||||
"deploy": false
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (this.registration && this.registration.rootDomain) {
|
||||
// Register root domain if it is defined
|
||||
const rootNode = namehash.hash(this.registration.rootDomain);
|
||||
config.development.contracts['FIFSRegistrar'] = {
|
||||
"deploy": true,
|
||||
"args": ["$ENSRegistry", rootNode],
|
||||
"onDeploy": [
|
||||
`ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send().then(() => {
|
||||
ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send();
|
||||
var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '${reverseAddrSuffix}');
|
||||
ENSRegistry.methods.setResolver(reverseNode, "$Resolver").send();
|
||||
Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send();
|
||||
Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send();
|
||||
})`
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
this.embark.registerContractConfiguration(config);
|
||||
|
||||
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/ENSRegistry.sol'));
|
||||
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/FIFSRegistrar.sol'));
|
||||
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/Resolver.sol'));
|
||||
}
|
||||
|
||||
addSetProvider(config) {
|
||||
|
||||
let code = "\nEmbarkJS.Names.setProvider('ens'," + JSON.stringify(config) + ");";
|
||||
|
@ -13,12 +13,46 @@ class Profiler {
|
||||
this.registerApi();
|
||||
}
|
||||
|
||||
profile(contractName, contract, callback) {
|
||||
profileJSON(contractName, returnCb) {
|
||||
const self = this;
|
||||
|
||||
let profileObj = {};
|
||||
profileObj.name = contractName;
|
||||
profileObj.methods = [];
|
||||
|
||||
self.events.request('contracts:contract', contractName, (contract) => {
|
||||
if (!contract || !contract.deployedAddress) {
|
||||
return returnCb("-- couldn't profile " + contractName + " - it's not deployed or could be an interface");
|
||||
}
|
||||
self.gasEstimator.estimateGas(contractName, function(_err, gastimates, _name) {
|
||||
contract.abiDefinition.forEach((abiMethod) => {
|
||||
let methodName = abiMethod.name;
|
||||
if (['constructor', 'fallback'].indexOf(abiMethod.type) >= 0) {
|
||||
methodName = abiMethod.type;
|
||||
}
|
||||
|
||||
profileObj.methods.push({
|
||||
name: methodName,
|
||||
payable: abiMethod.payable,
|
||||
mutability: abiMethod.stateMutability,
|
||||
inputs: abiMethod.inputs || [],
|
||||
outputs: abiMethod.outputs || [],
|
||||
gasEstimates: gastimates && gastimates[methodName]
|
||||
});
|
||||
});
|
||||
|
||||
returnCb(null, profileObj);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
profile(contractName, returnCb) {
|
||||
const self = this;
|
||||
|
||||
this.profileJSON(contractName, (err, profileObj) => {
|
||||
if (err) {
|
||||
return callback(null, "error found in method: " + name + " error: " + JSON.stringify(err));
|
||||
self.logger.error(JSON.stringify(err));
|
||||
return returnCb(err);
|
||||
}
|
||||
|
||||
let table = new asciiTable(contractName);
|
||||
@ -26,7 +60,7 @@ class Profiler {
|
||||
profileObj.methods.forEach((method) => {
|
||||
table.addRow(method.name, method.payable, method.mutability, self.formatParams(method.inputs), self.formatParams(method.outputs), method.gasEstimates);
|
||||
});
|
||||
callback(null, table.toString());
|
||||
return returnCb(null, table.toString());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -30,23 +30,26 @@ class Solidity {
|
||||
}
|
||||
|
||||
_compile(jsonObj, returnAllErrors, callback) {
|
||||
this.solcW.compile(jsonObj, (err, output) => {
|
||||
if (err) {
|
||||
const self = this;
|
||||
self.solcW.compile(jsonObj, function (err, output) {
|
||||
self.events.emit('contracts:compile:solc', jsonObj);
|
||||
|
||||
if(err){
|
||||
return callback(err);
|
||||
}
|
||||
if (output.errors && returnAllErrors) {
|
||||
return callback(output.errors);
|
||||
}
|
||||
|
||||
if (output.errors) {
|
||||
for (let i = 0; i < output.errors.length; i++) {
|
||||
for (let i=0; i<output.errors.length; i++) {
|
||||
if (output.errors[i].type === 'Warning') {
|
||||
this.logger.warn(output.errors[i].formattedMessage);
|
||||
self.logger.warn(output.errors[i].formattedMessage);
|
||||
}
|
||||
if (output.errors[i].type === 'Error' || output.errors[i].severity === 'error') {
|
||||
return callback(new Error("Solidity errors: " + output.errors[i].formattedMessage).message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.events.emit('contracts:compiled:solc', output);
|
||||
callback(null, output);
|
||||
});
|
||||
}
|
||||
@ -55,32 +58,6 @@ class Solidity {
|
||||
const self = this;
|
||||
|
||||
async.waterfall([
|
||||
function prepareInput(callback) {
|
||||
async.each(contractFiles,
|
||||
function(file, fileCb) {
|
||||
let filename = file.filename;
|
||||
|
||||
for (let directory of self.contractDirectories) {
|
||||
let match = new RegExp("^" + directory);
|
||||
filename = filename.replace(match, '');
|
||||
}
|
||||
|
||||
originalFilepath[filename] = file.filename;
|
||||
|
||||
file.content(function(fileContent) {
|
||||
if (!fileContent) {
|
||||
self.logger.error(__('Error while loading the content of ') + filename);
|
||||
return fileCb();
|
||||
}
|
||||
input[filename] = {content: fileContent.replace(/\r\n/g, '\n'), path: file.path};
|
||||
fileCb();
|
||||
});
|
||||
},
|
||||
function (err) {
|
||||
callback(err);
|
||||
}
|
||||
);
|
||||
},
|
||||
function loadCompiler(callback) {
|
||||
if (self.solcAlreadyLoaded) {
|
||||
return callback();
|
||||
@ -125,28 +102,7 @@ class Solidity {
|
||||
}
|
||||
};
|
||||
|
||||
self.solcW.compile(jsonObj, function (err, output) {
|
||||
self.events.emit('contracts:compile:solc', jsonObj);
|
||||
|
||||
if(err){
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (output.errors) {
|
||||
for (let i=0; i<output.errors.length; i++) {
|
||||
if (output.errors[i].type === 'Warning') {
|
||||
self.logger.warn(output.errors[i].formattedMessage);
|
||||
}
|
||||
if (output.errors[i].type === 'Error' || output.errors[i].severity === 'error') {
|
||||
return callback(new Error("Solidity errors: " + output.errors[i].formattedMessage).message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.events.emit('contracts:compiled:solc', output);
|
||||
|
||||
callback(null, output);
|
||||
});
|
||||
self._compile(jsonObj, returnAllErrors, callback);
|
||||
},
|
||||
function createCompiledObject(output, callback) {
|
||||
let json = output.contracts;
|
||||
|
@ -17,16 +17,16 @@ class WebServer {
|
||||
this.host = options.host || this.webServerConfig.host;
|
||||
this.port = options.port || this.webServerConfig.port;
|
||||
this.enableCatchAll = this.webServerConfig.enableCatchAll === true;
|
||||
this.enableCatchAll = false; // FIXME when true, some Requests end up failing (eg: process-logs)
|
||||
|
||||
this.events.emit("status", __("Starting Server"));
|
||||
this.server = new Server({host: this.host, port: this.port});
|
||||
this.server = new Server({logger: this.logger, host: this.host, port: this.port, events: this.events, plugins: this.plugins, enableCatchAll: this.enableCatchAll});
|
||||
|
||||
this.setServiceCheck();
|
||||
this.listenToCommands();
|
||||
this.registerConsoleCommands();
|
||||
|
||||
let self = this;
|
||||
this.server.start((_err, message) => self.logger.info(message));
|
||||
this.server.start((_err, message) => this.logger.info(message));
|
||||
}
|
||||
|
||||
setServiceCheck() {
|
||||
|
@ -13,14 +13,18 @@ class Server {
|
||||
this.dist = options.dist || 'dist/';
|
||||
this.port = options.port || 8000;
|
||||
this.hostname = dockerHostSwap(options.host) || defaultHost;
|
||||
this.logger = options.logger;
|
||||
this.plugins = options.plugins;
|
||||
this.enableCatchAll = options.enableCatchAll;
|
||||
}
|
||||
|
||||
start(callback) {
|
||||
callback = callback || function() {};
|
||||
const self = this;
|
||||
if (this.server && this.server.listening) {
|
||||
let message = __("a webserver is already running at") + " " +
|
||||
("http://" + canonicalHost(this.hostname) +
|
||||
":" + this.port).bold.underline.green;
|
||||
("http://" + canonicalHost(this.hostname) +
|
||||
":" + this.port).bold.underline.green;
|
||||
return callback(null, message);
|
||||
}
|
||||
var app = express();
|
||||
@ -54,13 +58,13 @@ class Server {
|
||||
app[apiCall.method].apply(app, [apiCall.endpoint, apiCall.cb]);
|
||||
});
|
||||
|
||||
app.get('/embark/*', function (req, res) {
|
||||
app.get('/embark/*', function(req, res) {
|
||||
self.logger.trace('webserver> GET ' + req.path);
|
||||
res.sendFile(path.join(__dirname, '../../../embark-ui/build', 'index.html'));
|
||||
});
|
||||
|
||||
if (this.enableCatchAll === true) {
|
||||
app.get('/*', function (req, res) {
|
||||
app.get('/*', function(req, res) {
|
||||
self.logger.trace('webserver> GET ' + req.path);
|
||||
res.sendFile(path.join(fs.dappPath(self.dist, 'index.html')));
|
||||
});
|
||||
@ -68,15 +72,14 @@ class Server {
|
||||
|
||||
app.listen(this.port);
|
||||
|
||||
let message = __("webserver available at") +
|
||||
" " +
|
||||
("http://" + canonicalHost(this.hostname) +
|
||||
":" + this.port).bold.underline.green;
|
||||
this.server.listen(this.port, this.hostname);
|
||||
callback(null, message);
|
||||
callback(null, __("webserver available at") +
|
||||
" " +
|
||||
("http://" + canonicalHost(this.hostname) +
|
||||
":" + this.port).bold.underline.green);
|
||||
}
|
||||
|
||||
stop(callback) {
|
||||
callback = callback || function () {};
|
||||
if (!this.server || !this.server.listening) {
|
||||
return callback(null, __("no webserver is currently running"));
|
||||
}
|
||||
|
@ -115,20 +115,29 @@ class WebpackProcess extends ProcessWrapper {
|
||||
presets: [
|
||||
[
|
||||
"@babel/preset-env", {
|
||||
modules: false,
|
||||
targets: {
|
||||
browsers: ["last 1 version", "not dead", "> 0.2%"]
|
||||
}
|
||||
modules: false,
|
||||
targets: {
|
||||
browsers: ["last 1 version", "not dead", "> 0.2%"]
|
||||
}
|
||||
}
|
||||
],
|
||||
"@babel/preset-react"
|
||||
].map(pkg => {
|
||||
if (Array.isArray(pkg)) {
|
||||
let _pkg = pkg[0];
|
||||
pkg[0] = require.resolve(_pkg);
|
||||
return pkg;
|
||||
} else {
|
||||
return require.resolve(pkg);
|
||||
}
|
||||
}),
|
||||
plugins: [
|
||||
"babel-plugin-webpack-aliases",
|
||||
[
|
||||
"@babel/plugin-transform-runtime", {
|
||||
corejs: 2,
|
||||
useESModules: true
|
||||
}
|
||||
corejs: 2,
|
||||
useESModules: true
|
||||
}
|
||||
]
|
||||
].map(pkg => {
|
||||
if (Array.isArray(pkg)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user