Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #180 from adjs/feature/allow_comments_in_json_files

allow comments in config, apiconfig, and data JSON files
  • Loading branch information...
commit dad590c1a0e5e88d8c36bf8b0837246fa9cb0ccc 2 parents 36bee11 + 603db78
@mansilladev mansilladev authored
Showing with 13 additions and 3 deletions.
  1. +4 −0 .gitignore
  2. +8 −3 app.js
  3. +1 −0  package.json
View
4 .gitignore
@@ -3,3 +3,7 @@ node_modules/*
config.json
logs/*
pids/*
+
+# Ignore project files
+.idea/*
+*.iml
View
11 app.js
@@ -39,6 +39,9 @@ var express = require('express'),
redis = require('redis'),
RedisStore = require('connect-redis')(express);
+// Add minify to the JSON object
+JSON.minify = JSON.minify || require("node-json-minify");
+
// Parse arguments
var yargs = require('yargs')
.usage('Usage: $0 --config-file [file]')
@@ -56,7 +59,8 @@ if (argv.help) {
// Configuration
var configFilePath = path.resolve(argv['config-file']);
try {
- var config = require(configFilePath);
+ var config = JSON.parse(JSON.minify(fs.readFileSync(configFilePath, 'utf8')));
+
} catch(e) {
console.error("File " + configFilePath + " not found or is invalid. Try: `cp config.json.sample config.json`");
process.exit(1);
@@ -97,7 +101,7 @@ if (!fs.existsSync(config.apiConfigDir)) {
}
try {
- var apisConfig = require(path.join(config.apiConfigDir, 'apiconfig.json'));
+ var apisConfig = JSON.parse(JSON.minify(fs.readFileSync(path.join(config.apiConfigDir, 'apiconfig.json'), 'utf8')));
if (config.debug) {
console.log(util.inspect(apisConfig));
}
@@ -953,7 +957,8 @@ function dynamicHelpers(req, res, next) {
if (req.params.api) {
res.locals.apiInfo = apisConfig[req.params.api];
res.locals.apiName = req.params.api;
- res.locals.apiDefinition = require(path.join(config.apiConfigDir, req.params.api + '.json'));
+ res.locals.apiDefinition = JSON.parse(JSON.minify(fs.readFileSync(path.join(config.apiConfigDir, req.params.api + '.json'), 'utf8')));
+
// If the cookie says we're authed for this particular API, set the session to authed as well
if (req.session[req.params.api] && req.session[req.params.api]['authed']) {
req.session['authed'] = true;
View
1  package.json
@@ -27,6 +27,7 @@
"connect-redis": "1.0.6",
"express": "3.3.1",
"jade": "0.32.0",
+ "node-json-minify": ">= 0.1.x",
"oauth": "0.9.10",
"redis": "0.8.3",
"querystring": "0.1.0",
Please sign in to comment.
Something went wrong with that request. Please try again.