Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
24 changes: 17 additions & 7 deletions dist/server/mongodb-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
})
}
}
Expand Down Expand Up @@ -525,4 +535,4 @@ function getBucketCount(from, to, intervalMs)
}

return count
}
}
13 changes: 4 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
24 changes: 17 additions & 7 deletions server/mongodb-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
})
}
}
Expand Down Expand Up @@ -525,4 +535,4 @@ function getBucketCount(from, to, intervalMs)
}

return count
}
}