diff --git a/.eslintrc.json b/.eslintrc.json index f92ef9b..a902a7b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -85,7 +85,7 @@ "max-classes-per-file": "error", "max-depth": "off", "max-len": "off", - "max-lines": "error", + "max-lines": "off", "max-lines-per-function": "off", "max-nested-callbacks": "error", "max-params": "off", diff --git a/src/parser/HttpParser.ts b/src/parser/HttpParser.ts index 67211aa..5ccf2ce 100644 --- a/src/parser/HttpParser.ts +++ b/src/parser/HttpParser.ts @@ -194,11 +194,6 @@ export class HttpParser { case "ERR_EMPTY_RESPONSE": this.res.socket.destroy() break; - // case "ERR_INVALID_HTTP_RESPONSE": - // this.res.socket.cork(); - // this.res.socket.write(Buffer.from("123sdlyndb;aie10-)(&2*2++1dnb/vlaj", 'utf-8')); - // this.res.socket.end(); - // break; case "ERR_INCOMPLETE_CHUNKED_ENCODING": this.res.writeHead(200); this.res.write('123sdlyndb;aie10-)(&2*2++1dnb/vlaj'); diff --git a/src/protocols/index.ts b/src/protocols/index.ts index bbcf1dd..aabd7ab 100644 --- a/src/protocols/index.ts +++ b/src/protocols/index.ts @@ -1,4 +1,6 @@ import express from "express"; +// @ts-ignore +import jp from 'jsonpath'; import fs from "fs"; import path from "path"; import http from "http"; @@ -109,53 +111,38 @@ export default class Protocols { logger.info(`Worker sharing gRPC server at ${grpcHost}:${grpcPort} ⛳`); server.start(); }); - packages.forEach((pkg: any) => { - let services: any[] = []; - let getObject = function (pkg: any) { - for (var prop in pkg) { - if (prop == 'service') { - services.push(pkg[prop]); - break; + const services: any[] = jp.query(packages, "$..service"); + services.forEach((service) => { + let methods = Object.keys(service); + methods.forEach((method) => { + if (!service[method]["responseStream"] && !service[method]["requestStream"]) { + if (server.register(service[method]["path"], grpcParser.camouflageMock, service[method]["responseSerialize"], service[method]["requestDeserialize"], 'unary')) { + logger.debug(`Registering Unary method: ${method}`); } else { - if (pkg[prop] instanceof Object) { - getObject(pkg[prop]); - } + logger.warn(`Not re-registering ${method}. Already registered.`) } } - } - getObject(pkg); - services.forEach((service) => { - let methods = Object.keys(service); - methods.forEach((method) => { - if (!service[method]["responseStream"] && !service[method]["requestStream"]) { - if (server.register(service[method]["path"], grpcParser.camouflageMock, service[method]["responseSerialize"], service[method]["requestDeserialize"], 'unary')) { - logger.debug(`Registering Unary method: ${method}`); - } else { - logger.warn(`Not re-registering ${method}. Already registered.`) - } - } - if (service[method]["responseStream"] && !service[method]["requestStream"]) { - if (server.register(service[method]["path"], grpcParser.camouflageMockServerStream, service[method]["responseSerialize"], service[method]["requestDeserialize"], 'serverStream')) { - logger.debug(`Registering method with server side streaming: ${method}`); - } else { - logger.warn(`Not re-registering ${method}. Already registered.`) - } + if (service[method]["responseStream"] && !service[method]["requestStream"]) { + if (server.register(service[method]["path"], grpcParser.camouflageMockServerStream, service[method]["responseSerialize"], service[method]["requestDeserialize"], 'serverStream')) { + logger.debug(`Registering method with server side streaming: ${method}`); + } else { + logger.warn(`Not re-registering ${method}. Already registered.`) } - if (!service[method]["responseStream"] && service[method]["requestStream"]) { - if (server.register(service[method]["path"], grpcParser.camouflageMockClientStream, service[method]["responseSerialize"], service[method]["requestDeserialize"], 'clientStream')) { - logger.debug(`Registering method with client side streaming: ${method}`); - } else { - logger.warn(`Not re-registering ${method}. Already registered.`) - } + } + if (!service[method]["responseStream"] && service[method]["requestStream"]) { + if (server.register(service[method]["path"], grpcParser.camouflageMockClientStream, service[method]["responseSerialize"], service[method]["requestDeserialize"], 'clientStream')) { + logger.debug(`Registering method with client side streaming: ${method}`); + } else { + logger.warn(`Not re-registering ${method}. Already registered.`) } - if (service[method]["responseStream"] && service[method]["requestStream"]) { - if (server.register(service[method]["path"], grpcParser.camouflageMockBidiStream, service[method]["responseSerialize"], service[method]["requestDeserialize"], 'bidi')) { - logger.debug(`Registering method with BIDI streaming: ${method}`); - } else { - logger.warn(`Not re-registering ${method}. Already registered.`) - } + } + if (service[method]["responseStream"] && service[method]["requestStream"]) { + if (server.register(service[method]["path"], grpcParser.camouflageMockBidiStream, service[method]["responseSerialize"], service[method]["requestDeserialize"], 'bidi')) { + logger.debug(`Registering method with BIDI streaming: ${method}`); + } else { + logger.warn(`Not re-registering ${method}. Already registered.`) } - }); + } }); }); };