diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..809935b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +from node:lts-alpine + +WORKDIR /app +COPY dist/server /app +COPY package.json /app + +RUN npm install --production + +VOLUME /app/config +EXPOSE 3333 + +CMD node mongodb-proxy.js diff --git a/dist/server/mongodb-proxy.js b/dist/server/mongodb-proxy.js index a3fc84e..a1d0cf6 100644 --- a/dist/server/mongodb-proxy.js +++ b/dist/server/mongodb-proxy.js @@ -188,13 +188,21 @@ function forIn(obj, processFunc) var key; for (key in obj) { - var value = obj[key] - processFunc(obj, key, value) - if ( value != null && typeof(value) == "object") + obj[key] = processFunc(obj, key, obj[key]) + if ( obj[key] != null && typeof(obj[key]) == "object") { - forIn(value, processFunc) + obj[key] = forIn(obj[key], processFunc) } } + + if ( + !Array.isArray(obj) && Object.keys(obj).length === 1 && + typeof obj['$date'] !== 'undefined' + ) { + return new Date(obj['$date']); + } + + return obj; } function parseQuery(query, substitutions) @@ -256,15 +264,17 @@ function parseQuery(query, substitutions) for ( var i = 0; i < doc.pipeline.length; i++) { var stage = doc.pipeline[i] - forIn(stage, function (obj, key, value) + stage = forIn(stage, function (obj, key, value) { if ( typeof(value) == "string" ) { if ( value in substitutions ) { - obj[key] = substitutions[value] + return substitutions[value] } } + + return value; }) } } @@ -525,4 +535,4 @@ function getBucketCount(from, to, intervalMs) } return count -} \ No newline at end of file +} diff --git a/package.json b/package.json index 5e63bd8..514c907 100644 --- a/package.json +++ b/package.json @@ -18,12 +18,11 @@ "bugs": { "url": "https://github.com/JamesOsgood/mongodb-grafana/issues" }, - "engines": { - "node": "6.10.0" - }, - "engineStrict": true, "devDependencies": { "babel": "^6.23.0", + "babel-plugin-transform-es2015-for-of": "^6.6.0", + "babel-plugin-transform-es2015-modules-systemjs": "^6.24.1", + "babel-preset-es2015": "^6.24.1", "chai": "~3.5.0", "grunt": "^1.0.3", "grunt-babel": "~6.0.0", @@ -37,19 +36,15 @@ "grunt-systemjs-builder": "^1.0.0", "jsdom": "~9.12.0", "load-grunt-tasks": "^3.5.2", + "mocha": "^5.2.0", "prunk": "^1.3.0", "q": "^1.5.0" }, "dependencies": { - "babel-plugin-transform-es2015-for-of": "^6.6.0", - "babel-plugin-transform-es2015-modules-systemjs": "^6.24.1", - "babel-preset-es2015": "^6.24.1", "body-parser": "^1.18.3", "config": "^1.30.0", "express": "^4.16.3", - "fs": "0.0.1-security", "lodash": "^4.17.10", - "mocha": "^5.2.0", "moment": "^2.22.1", "mongodb": "^3.0.8", "statman-stopwatch": "^2.7.0" diff --git a/server/mongodb-proxy.js b/server/mongodb-proxy.js index a3fc84e..a1d0cf6 100644 --- a/server/mongodb-proxy.js +++ b/server/mongodb-proxy.js @@ -188,13 +188,21 @@ function forIn(obj, processFunc) var key; for (key in obj) { - var value = obj[key] - processFunc(obj, key, value) - if ( value != null && typeof(value) == "object") + obj[key] = processFunc(obj, key, obj[key]) + if ( obj[key] != null && typeof(obj[key]) == "object") { - forIn(value, processFunc) + obj[key] = forIn(obj[key], processFunc) } } + + if ( + !Array.isArray(obj) && Object.keys(obj).length === 1 && + typeof obj['$date'] !== 'undefined' + ) { + return new Date(obj['$date']); + } + + return obj; } function parseQuery(query, substitutions) @@ -256,15 +264,17 @@ function parseQuery(query, substitutions) for ( var i = 0; i < doc.pipeline.length; i++) { var stage = doc.pipeline[i] - forIn(stage, function (obj, key, value) + stage = forIn(stage, function (obj, key, value) { if ( typeof(value) == "string" ) { if ( value in substitutions ) { - obj[key] = substitutions[value] + return substitutions[value] } } + + return value; }) } } @@ -525,4 +535,4 @@ function getBucketCount(from, to, intervalMs) } return count -} \ No newline at end of file +}