Skip to content

Commit cb1deee

Browse files
authored
Merge pull request #1 from thecodesmith/docker-image
Docker image and Node update
2 parents 4cefb88 + 2b3fcc2 commit cb1deee

File tree

4 files changed

+50
-23
lines changed

4 files changed

+50
-23
lines changed

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from node:lts-alpine
2+
3+
WORKDIR /app
4+
COPY dist/server /app
5+
COPY package.json /app
6+
7+
RUN npm install --production
8+
9+
VOLUME /app/config
10+
EXPOSE 3333
11+
12+
CMD node mongodb-proxy.js

dist/server/mongodb-proxy.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,21 @@ function forIn(obj, processFunc)
188188
var key;
189189
for (key in obj)
190190
{
191-
var value = obj[key]
192-
processFunc(obj, key, value)
193-
if ( value != null && typeof(value) == "object")
191+
obj[key] = processFunc(obj, key, obj[key])
192+
if ( obj[key] != null && typeof(obj[key]) == "object")
194193
{
195-
forIn(value, processFunc)
194+
obj[key] = forIn(obj[key], processFunc)
196195
}
197196
}
197+
198+
if (
199+
!Array.isArray(obj) && Object.keys(obj).length === 1 &&
200+
typeof obj['$date'] !== 'undefined'
201+
) {
202+
return new Date(obj['$date']);
203+
}
204+
205+
return obj;
198206
}
199207

200208
function parseQuery(query, substitutions)
@@ -256,15 +264,17 @@ function parseQuery(query, substitutions)
256264
for ( var i = 0; i < doc.pipeline.length; i++)
257265
{
258266
var stage = doc.pipeline[i]
259-
forIn(stage, function (obj, key, value)
267+
stage = forIn(stage, function (obj, key, value)
260268
{
261269
if ( typeof(value) == "string" )
262270
{
263271
if ( value in substitutions )
264272
{
265-
obj[key] = substitutions[value]
273+
return substitutions[value]
266274
}
267275
}
276+
277+
return value;
268278
})
269279
}
270280
}
@@ -525,4 +535,4 @@ function getBucketCount(from, to, intervalMs)
525535
}
526536

527537
return count
528-
}
538+
}

package.json

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
"bugs": {
1919
"url": "https://github.com/JamesOsgood/mongodb-grafana/issues"
2020
},
21-
"engines": {
22-
"node": "6.10.0"
23-
},
24-
"engineStrict": true,
2521
"devDependencies": {
2622
"babel": "^6.23.0",
23+
"babel-plugin-transform-es2015-for-of": "^6.6.0",
24+
"babel-plugin-transform-es2015-modules-systemjs": "^6.24.1",
25+
"babel-preset-es2015": "^6.24.1",
2726
"chai": "~3.5.0",
2827
"grunt": "^1.0.3",
2928
"grunt-babel": "~6.0.0",
@@ -37,19 +36,15 @@
3736
"grunt-systemjs-builder": "^1.0.0",
3837
"jsdom": "~9.12.0",
3938
"load-grunt-tasks": "^3.5.2",
39+
"mocha": "^5.2.0",
4040
"prunk": "^1.3.0",
4141
"q": "^1.5.0"
4242
},
4343
"dependencies": {
44-
"babel-plugin-transform-es2015-for-of": "^6.6.0",
45-
"babel-plugin-transform-es2015-modules-systemjs": "^6.24.1",
46-
"babel-preset-es2015": "^6.24.1",
4744
"body-parser": "^1.18.3",
4845
"config": "^1.30.0",
4946
"express": "^4.16.3",
50-
"fs": "0.0.1-security",
5147
"lodash": "^4.17.10",
52-
"mocha": "^5.2.0",
5348
"moment": "^2.22.1",
5449
"mongodb": "^3.0.8",
5550
"statman-stopwatch": "^2.7.0"

server/mongodb-proxy.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,21 @@ function forIn(obj, processFunc)
188188
var key;
189189
for (key in obj)
190190
{
191-
var value = obj[key]
192-
processFunc(obj, key, value)
193-
if ( value != null && typeof(value) == "object")
191+
obj[key] = processFunc(obj, key, obj[key])
192+
if ( obj[key] != null && typeof(obj[key]) == "object")
194193
{
195-
forIn(value, processFunc)
194+
obj[key] = forIn(obj[key], processFunc)
196195
}
197196
}
197+
198+
if (
199+
!Array.isArray(obj) && Object.keys(obj).length === 1 &&
200+
typeof obj['$date'] !== 'undefined'
201+
) {
202+
return new Date(obj['$date']);
203+
}
204+
205+
return obj;
198206
}
199207

200208
function parseQuery(query, substitutions)
@@ -256,15 +264,17 @@ function parseQuery(query, substitutions)
256264
for ( var i = 0; i < doc.pipeline.length; i++)
257265
{
258266
var stage = doc.pipeline[i]
259-
forIn(stage, function (obj, key, value)
267+
stage = forIn(stage, function (obj, key, value)
260268
{
261269
if ( typeof(value) == "string" )
262270
{
263271
if ( value in substitutions )
264272
{
265-
obj[key] = substitutions[value]
273+
return substitutions[value]
266274
}
267275
}
276+
277+
return value;
268278
})
269279
}
270280
}
@@ -525,4 +535,4 @@ function getBucketCount(from, to, intervalMs)
525535
}
526536

527537
return count
528-
}
538+
}

0 commit comments

Comments
 (0)