resolve conflict in api and saga
This commit is contained in:
parent
e9ec0c019d
commit
324e148fa6
|
@ -62,7 +62,10 @@ class ConsoleListener {
|
||||||
_listenForLogRequests() {
|
_listenForLogRequests() {
|
||||||
if (this.ipc.ipcRole !== 'server') return;
|
if (this.ipc.ipcRole !== 'server') return;
|
||||||
this.ipc.on('log', (request) => {
|
this.ipc.on('log', (request) => {
|
||||||
if (request.type === 'contract-log') {
|
if (request.type !== 'contract-log') {
|
||||||
|
return this.logger.info(JSON.stringify(request));
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.contractsDeployed) return;
|
if (!this.contractsDeployed) return;
|
||||||
|
|
||||||
let {address, data, transactionHash, blockNumber, gasUsed, status} = request;
|
let {address, data, transactionHash, blockNumber, gasUsed, status} = request;
|
||||||
|
@ -98,9 +101,6 @@ class ConsoleListener {
|
||||||
this.events.emit('contracts:log', this.logs[this.logs.length - 1]);
|
this.events.emit('contracts:log', this.logs[this.logs.length - 1]);
|
||||||
|
|
||||||
this.logger.info(`Blockchain>`.underline + ` ${name}.${functionName}(${paramString})`.bold + ` | ${transactionHash} | gas:${gasUsed} | blk:${blockNumber} | status:${status}`);
|
this.logger.info(`Blockchain>`.underline + ` ${name}.${functionName}(${paramString})`.bold + ` | ${transactionHash} | gas:${gasUsed} | blk:${blockNumber} | status:${status}`);
|
||||||
} else {
|
|
||||||
this.logger.info(JSON.stringify(request));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ class Server {
|
||||||
const main = serveStatic(this.buildDir, {'index': ['index.html', 'index.htm']});
|
const main = serveStatic(this.buildDir, {'index': ['index.html', 'index.htm']});
|
||||||
|
|
||||||
this.app = express();
|
this.app = express();
|
||||||
|
const expressWs = expressWebSocket(this.app);
|
||||||
// Assign Logging Function
|
// Assign Logging Function
|
||||||
this.app.use(function(req, res, next) {
|
this.app.use(function(req, res, next) {
|
||||||
if (self.logging) {
|
if (self.logging) {
|
||||||
|
@ -64,7 +65,6 @@ class Server {
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
expressWebSocket(this.app);
|
|
||||||
|
|
||||||
this.app.use(helmet.noCache());
|
this.app.use(helmet.noCache());
|
||||||
this.app.use(cors());
|
this.app.use(cors());
|
||||||
|
@ -97,16 +97,15 @@ class Server {
|
||||||
this.app[apiCall.method].apply(this.app, [apiCall.endpoint, this.applyAPIFunction.bind(this, apiCall.cb)]);
|
this.app[apiCall.method].apply(this.app, [apiCall.endpoint, this.applyAPIFunction.bind(this, apiCall.cb)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const wss = expressWs.getWss('/');
|
||||||
|
|
||||||
this.app.ws('/', function(ws, _req) {
|
|
||||||
self.events.on('outputDone', () => {
|
self.events.on('outputDone', () => {
|
||||||
if (ws.readyState === WEB_SOCKET_STATE_OPEN) {
|
wss.clients.forEach(function (client) {
|
||||||
return ws.send('outputDone');
|
client.send('outputDone');
|
||||||
}
|
});
|
||||||
// if the socket wasn't yet opened, listen for the 'open' event,
|
self.events.on('outputError', () => {
|
||||||
// then send the 'outputDone' data
|
wss.clients.forEach(function (client) {
|
||||||
ws.addEventListener('open', _event => {
|
client.send('outputError');
|
||||||
ws.send('outputDone');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -164,7 +163,13 @@ class Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
applyAPIFunction (cb, req, res) {
|
applyAPIFunction (cb, req, res) {
|
||||||
this.events.request('authenticator:authorize', req.headers.authorization, (err) => {
|
// FIXME Need to not authenticate WS request as they do not pass the toekn in the header yet
|
||||||
|
const authToken = (!res.send) ? req.protocol : req.headers.authorization;
|
||||||
|
if (!res.send) {
|
||||||
|
// console.dir(arguments);
|
||||||
|
return cb(req, res);
|
||||||
|
}
|
||||||
|
this.events.request('authenticator:authorize', authToken, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
const send = res.send ? res.send.bind(res) : req.send.bind(req); // WS only has the first params
|
const send = res.send ? res.send.bind(res) : req.send.bind(req); // WS only has the first params
|
||||||
return send(err);
|
return send(err);
|
||||||
|
|
Loading…
Reference in New Issue