mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-09 13:36:14 +00:00
small conflicts
This commit is contained in:
parent
775238af4c
commit
665d344a54
@ -18,7 +18,7 @@ Logger.prototype.registerAPICall = function (plugins) {
|
|||||||
plugin.registerAPICall(
|
plugin.registerAPICall(
|
||||||
'ws',
|
'ws',
|
||||||
'/embark-api/logs',
|
'/embark-api/logs',
|
||||||
(ws, req) => {
|
(ws, _req) => {
|
||||||
self.events.on("log", function(logLevel, logMsg) {
|
self.events.on("log", function(logLevel, logMsg) {
|
||||||
ws.send(JSON.stringify({msg: logMsg, msg_clear: logMsg.stripColors, logLevel: logLevel}), () => {});
|
ws.send(JSON.stringify({msg: logMsg, msg_clear: logMsg.stripColors, logLevel: logLevel}), () => {});
|
||||||
});
|
});
|
||||||
@ -26,7 +26,7 @@ Logger.prototype.registerAPICall = function (plugins) {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger.prototype.writeToFile = function (txt) {
|
Logger.prototype.writeToFile = function (_txt) {
|
||||||
if (!this.logfile) {
|
if (!this.logfile) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ var Plugin = function(options) {
|
|||||||
this.pluginTypes = [];
|
this.pluginTypes = [];
|
||||||
this.uploadCmds = [];
|
this.uploadCmds = [];
|
||||||
this.apiCalls = [];
|
this.apiCalls = [];
|
||||||
|
this.processes = [];
|
||||||
this.imports = [];
|
this.imports = [];
|
||||||
this.embarkjs_code = [];
|
this.embarkjs_code = [];
|
||||||
this.embarkjs_init_code = {};
|
this.embarkjs_init_code = {};
|
||||||
@ -213,7 +214,12 @@ Plugin.prototype.registerActionForEvent = function(eventName, cb) {
|
|||||||
Plugin.prototype.registerAPICall = function(method, endpoint, cb) {
|
Plugin.prototype.registerAPICall = function(method, endpoint, cb) {
|
||||||
console.dir("registerAPICall " + method + " " + endpoint);
|
console.dir("registerAPICall " + method + " " + endpoint);
|
||||||
this.apiCalls.push({method: method, endpoint: endpoint, cb: cb});
|
this.apiCalls.push({method: method, endpoint: endpoint, cb: cb});
|
||||||
this.pluginTypes.push('apiCalls');
|
this.addPluginType('apiCalls');
|
||||||
|
};
|
||||||
|
|
||||||
|
Plugin.prototype.registerProcess = function(processName) {
|
||||||
|
this.processes.push({processName});
|
||||||
|
this.addPluginType('processes');
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.runFilePipeline = function() {
|
Plugin.prototype.runFilePipeline = function() {
|
||||||
|
@ -14,15 +14,19 @@ class ProcessLauncher {
|
|||||||
* @return {ProcessLauncher} The ProcessLauncher instance
|
* @return {ProcessLauncher} The ProcessLauncher instance
|
||||||
*/
|
*/
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.name = path.basename(options.modulePath);
|
this.name = options.name || path.basename(options.modulePath);
|
||||||
this.process = child_process.fork(options.modulePath);
|
this.process = child_process.fork(options.modulePath);
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
this.events = options.events;
|
this.events = options.events;
|
||||||
this.silent = options.silent;
|
this.silent = options.silent;
|
||||||
this.exitCallback = options.exitCallback;
|
this.exitCallback = options.exitCallback;
|
||||||
|
this.embark = options.embark;
|
||||||
|
|
||||||
this.subscriptions = {};
|
this.subscriptions = {};
|
||||||
this._subscribeToMessages();
|
this._subscribeToMessages();
|
||||||
|
if (this.embark) {
|
||||||
|
this._registerAsPlugin();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subscribes to messages from the child process and delegates to the right methods
|
// Subscribes to messages from the child process and delegates to the right methods
|
||||||
@ -48,8 +52,22 @@ class ProcessLauncher {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_registerAsPlugin() {
|
||||||
|
const self = this;
|
||||||
|
self.embark.registerAPICall(
|
||||||
|
'ws',
|
||||||
|
'/embark/process-logs/' + self.name,
|
||||||
|
(ws, _req) => {
|
||||||
|
self.events.on('log-' + self.name, function(logLevel, msg) {
|
||||||
|
ws.send(JSON.stringify({msg, msg_clear: msg.stripColors, logLevel}), () => {});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Translates logs from the child process to the logger
|
// Translates logs from the child process to the logger
|
||||||
_handleLog(msg) {
|
_handleLog(msg) {
|
||||||
|
this.events.emit('log-' + this.name, msg.type, msg.message);
|
||||||
if (this.silent && msg.type !== 'error') {
|
if (this.silent && msg.type !== 'error') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,35 @@
|
|||||||
|
|
||||||
class ProcessManager {
|
class ProcessManager {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
const self = this;
|
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
this.events = options.events;
|
this.events = options.events;
|
||||||
this.plugins = options.plugins;
|
this.plugins = options.plugins;
|
||||||
this.processes = {};
|
this.processes = {};
|
||||||
|
|
||||||
|
this._registerAsPlugin();
|
||||||
|
this._registerEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
_registerAsPlugin() {
|
||||||
|
const self =this;
|
||||||
|
self.plugin = this.plugins.createPlugin('processManager', {});
|
||||||
|
self.plugin.registerAPICall(
|
||||||
|
'get',
|
||||||
|
'/embark/processes',
|
||||||
|
(req, res) => {
|
||||||
|
let parsedProcesses = {};
|
||||||
|
Object.keys(self.processes).forEach(processName => {
|
||||||
|
parsedProcesses[processName] = {
|
||||||
|
state: self.processes[processName]
|
||||||
|
};
|
||||||
|
});
|
||||||
|
res.send(parsedProcesses);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_registerEvents() {
|
||||||
|
const self = this;
|
||||||
self.events.setCommandHandler('processes:register', (name, cb) => {
|
self.events.setCommandHandler('processes:register', (name, cb) => {
|
||||||
this.processes[name] = {
|
this.processes[name] = {
|
||||||
state: 'unstarted',
|
state: 'unstarted',
|
||||||
@ -16,7 +39,7 @@ class ProcessManager {
|
|||||||
|
|
||||||
self.events.setCommandHandler('processes:launch', (name, cb) => {
|
self.events.setCommandHandler('processes:launch', (name, cb) => {
|
||||||
let process = self.processes[name];
|
let process = self.processes[name];
|
||||||
if (process.state != 'unstarted') {
|
if (process.state !== 'unstarted') {
|
||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
process.state = 'starting';
|
process.state = 'starting';
|
||||||
@ -28,7 +51,6 @@ class ProcessManager {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ProcessManager;
|
module.exports = ProcessManager;
|
||||||
|
@ -19,6 +19,10 @@ class IPFS {
|
|||||||
this.webServerConfig = embark.config.webServerConfig;
|
this.webServerConfig = embark.config.webServerConfig;
|
||||||
this.blockchainConfig = embark.config.blockchainConfig;
|
this.blockchainConfig = embark.config.blockchainConfig;
|
||||||
|
|
||||||
|
this.events.request('processes:register', 'ipfs', (cb) => {
|
||||||
|
self.startProcess(cb);
|
||||||
|
});
|
||||||
|
|
||||||
if (this.isIpfsStorageEnabledInTheConfig() || this.isIpfsNameEnabledInTheConfig()) {
|
if (this.isIpfsStorageEnabledInTheConfig() || this.isIpfsNameEnabledInTheConfig()) {
|
||||||
this.downloadIpfsApi();
|
this.downloadIpfsApi();
|
||||||
this.addDefaultToEmbarkJS();
|
this.addDefaultToEmbarkJS();
|
||||||
@ -35,7 +39,7 @@ class IPFS {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.logger.info("IPFS node not found, attempting to start own node");
|
self.logger.info("IPFS node not found, attempting to start own node");
|
||||||
self.startProcess(() => {});
|
this.events.request("processes:launch", "ipfs", () => {});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +149,8 @@ class IPFS {
|
|||||||
events: self.events,
|
events: self.events,
|
||||||
storageConfig: self.storageConfig,
|
storageConfig: self.storageConfig,
|
||||||
webServerConfig: self.webServerConfig,
|
webServerConfig: self.webServerConfig,
|
||||||
blockchainConfig: self.blockchainConfig
|
blockchainConfig: self.blockchainConfig,
|
||||||
|
embark: self.embark
|
||||||
});
|
});
|
||||||
self.logger.trace(`Storage module: Launching ipfs process...`);
|
self.logger.trace(`Storage module: Launching ipfs process...`);
|
||||||
return storageProcessesLauncher.launchProcess('ipfs', callback);
|
return storageProcessesLauncher.launchProcess('ipfs', callback);
|
||||||
|
@ -17,6 +17,7 @@ class StorageProcessesLauncher {
|
|||||||
this.storageConfig = options.storageConfig;
|
this.storageConfig = options.storageConfig;
|
||||||
this.webServerConfig = options.webServerConfig;
|
this.webServerConfig = options.webServerConfig;
|
||||||
this.blockchainConfig = options.blockchainConfig;
|
this.blockchainConfig = options.blockchainConfig;
|
||||||
|
this.embark = options.embark;
|
||||||
this.processes = {};
|
this.processes = {};
|
||||||
|
|
||||||
this.cors = this.buildCors();
|
this.cors = this.buildCors();
|
||||||
@ -105,8 +106,10 @@ class StorageProcessesLauncher {
|
|||||||
self.logger.info(__(`Starting %s process`, storageName).cyan);
|
self.logger.info(__(`Starting %s process`, storageName).cyan);
|
||||||
self.processes[storageName] = new ProcessLauncher({
|
self.processes[storageName] = new ProcessLauncher({
|
||||||
modulePath: filePath,
|
modulePath: filePath,
|
||||||
|
name: storageName,
|
||||||
logger: self.logger,
|
logger: self.logger,
|
||||||
events: self.events,
|
events: self.events,
|
||||||
|
embark: self.embark,
|
||||||
silent: self.logger.logLevel !== 'trace',
|
silent: self.logger.logLevel !== 'trace',
|
||||||
exitCallback: self.processExited.bind(this, storageName)
|
exitCallback: self.processExited.bind(this, storageName)
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
let finalhandler = require('finalhandler');
|
|
||||||
let http = require('http');
|
|
||||||
let serveStatic = require('serve-static');
|
let serveStatic = require('serve-static');
|
||||||
const {canonicalHost, defaultHost, dockerHostSwap} = require('../../utils/host');
|
const {canonicalHost, defaultHost, dockerHostSwap} = require('../../utils/host');
|
||||||
require('http-shutdown').extend();
|
require('http-shutdown').extend();
|
||||||
@ -28,11 +26,11 @@ class Server {
|
|||||||
}
|
}
|
||||||
var app = express();
|
var app = express();
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use(express.static(path.join(fs.dappPath(this.dist)), {'index': ['index.html', 'index.htm']}));
|
app.use(express.static(path.join(fs.dappPath(this.dist)), {'index': ['index.html', 'index.htm']}));
|
||||||
app.use('/embark', express.static(path.join(__dirname, '../../../embark-ui/build')));
|
app.use('/embark', express.static(path.join(__dirname, '../../../embark-ui/build')));
|
||||||
|
|
||||||
app.use(bodyParser.json()); // support json encoded bodies
|
app.use(bodyParser.json()); // support json encoded bodies
|
||||||
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
|
app.use(bodyParser.urlencoded({extended: true})); // support encoded bodies
|
||||||
|
|
||||||
expressWebSocket(app);
|
expressWebSocket(app);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user