From 33387bbd3322ca8a1513c6c1513350b6011ad640 Mon Sep 17 00:00:00 2001 From: Carlos Justiniano Date: Thu, 10 Jan 2019 01:18:00 -0500 Subject: [PATCH 1/2] support for loggly post init (#184) * Experimental GZip support * updated stack up / down scripts * bump version * Fix for loading dashboard * fix for loading logger after hydra is initialized * update to node 10 alpine image * support for loggly post init. --- Dockerfile | 2 +- hydra-router.js | 7 +++++++ lib/servicerouter.js | 10 ++++++++++ package.json | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index e2780ef..2ba599f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:8.11-alpine +FROM node:10-alpine LABEL maintainer="Carlos Justiniano cjus34@gmail.com" EXPOSE 80 ENV UV_THREADPOOL_SIZE 64 diff --git a/hydra-router.js b/hydra-router.js index b1218a1..2fb9f41 100644 --- a/hydra-router.js +++ b/hydra-router.js @@ -217,6 +217,7 @@ let main = async() => { let newConfig = await hydra.init(`${__dirname}/config/config.json`, false); config = newConfig; + let serviceInfo = await hydra.registerService(); let logEntry = `Starting service ${serviceInfo.serviceName}:${hydra.getInstanceVersion()} on ${serviceInfo.serviceIP}:${serviceInfo.servicePort}`; @@ -227,6 +228,12 @@ let main = async() => { }; } + if (loggerType === 'loggly') { + hydraLogger.setHydra(hydra); + hydraLogger.setConfig(config.hydra); + hydraLogger.onServiceReady(); + } + setupExitHandlers(); displayBanner(); displayNetworkInterfaces(); diff --git a/lib/servicerouter.js b/lib/servicerouter.js index 0934f5b..f44b7a4 100644 --- a/lib/servicerouter.js +++ b/lib/servicerouter.js @@ -903,6 +903,16 @@ class ServiceRouter { } } + let resourcePath = urlData.pathname; + if (resourcePath.endsWith('.css') || + resourcePath.endsWith('.js') || + resourcePath.endsWith('.ttf') || + resourcePath.endsWith('.woff') || + resourcePath.endsWith('.woff2') + ) { + allowRouterCall = true; + } + if (urlData.host !== 'localhost' && !allowRouterCall) { serverResponse.sendResponse(ServerResponse.HTTP_NOT_FOUND, response); return; diff --git a/package.json b/package.json index 0fbacef..f99667f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hydra-router", - "version": "1.6.16", + "version": "1.6.20", "description": "A service which routes requests to hydra-based microservices", "author": { "name": "Carlos Justiniano", From c66a710fe227c56434758d508cf6a3ff5432cab6 Mon Sep 17 00:00:00 2001 From: Sif Date: Mon, 10 Feb 2020 22:16:44 -0500 Subject: [PATCH 2/2] Convert form-url encoded content-type to json & use qs parser (#185) * Convert content-type to json & use qs parser - `Utils.safeJSONParse` uses `JSON.parse` under the hood which cannot convert form url encoded query strings (which is what the string format of the binary data/Buffer string would be) to a "JSON Object" so we'll use the core node.js module, `querystring` to parse it. However, this parser might not automagically convert the Buffer to a string, so we'll convert it first and then parse it using the correct parser. - For some reason, we need to have the `content-type` to use `application/json`. This is no matter if the body is correctly parsed or not. My guess is there is some method in `hydra` library that requires the header content type to be json rather or the body is parsed in a string format rather than a JSON format. This change seems to be the cleanest with minimal changes to the surface area without also updating any other libraries. Previously, we are unable to send any requests with form url encoded body params whereas now form url encoded body params will be converted to json body params. * Minor bump version from 1.6.20 -> 1.7.0 * Remove speculated comment --- lib/servicerouter.js | 11 ++++++++++- package.json | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/servicerouter.js b/lib/servicerouter.js index f44b7a4..ae4a219 100644 --- a/lib/servicerouter.js +++ b/lib/servicerouter.js @@ -779,7 +779,16 @@ class ServiceRouter { headers: Object.assign({}, request.headers) }; - message.body = Utils.safeJSONParse(body) || {}; + if (request.headers['content-type'] === 'application/x-www-form-urlencoded') { + message.headers['content-type'] = 'application/json'; + try { + message.body = querystring.parse(body.toString()); + } catch (e) { + message.body = {}; + } + } else { + message.body = Utils.safeJSONParse(body) || {}; + } if (request.headers['authorization']) { message.authorization = request.headers['authorization']; diff --git a/package.json b/package.json index f99667f..221e3bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hydra-router", - "version": "1.6.20", + "version": "1.7.0", "description": "A service which routes requests to hydra-based microservices", "author": { "name": "Carlos Justiniano",