diff options
author | Mark Engel <mark.c.engel@gmail.com> | 2011-01-23 13:03:37 +0100 |
---|---|---|
committer | Mark Engel <mark.c.engel@gmail.com> | 2011-01-23 13:03:37 +0100 |
commit | 30fb6b81a2eb73f78fb621079a2e4332fd53a31f (patch) | |
tree | 5e84d37491ec1d4bb8aff20e9768e775b06ec174 | |
parent | 899e3223fe599deb295eaa4068dcb48ccb1f1f2c (diff) | |
download | osm-xapi-30fb6b81a2eb73f78fb621079a2e4332fd53a31f.tar.gz osm-xapi-30fb6b81a2eb73f78fb621079a2e4332fd53a31f.tar.xz osm-xapi-30fb6b81a2eb73f78fb621079a2e4332fd53a31f.zip |
config is now a real json file
update your custom configs!
Diffstat (limited to '')
-rw-r--r-- | src/nodejs/config.json | 11 | ||||
-rw-r--r-- | src/nodejs/main.js | 56 | ||||
-rw-r--r-- | src/nodejs/xmlGenerator.js | 4 |
3 files changed, 39 insertions, 32 deletions
diff --git a/src/nodejs/config.json b/src/nodejs/config.json index be796a7..92b4484 100644 --- a/src/nodejs/config.json +++ b/src/nodejs/config.json @@ -1,4 +1,7 @@ -exports.connectionString = "pg://user:password@host/database"; -exports.host = 'localhost'; -exports.port = 8080; -exports.logLevel = 'ERROR'; +{ + "connectionString": "pg://user:password@host/database", + "host": "localhost", + "port": 8080, + "logLevel": "ERROR" +} + diff --git a/src/nodejs/main.js b/src/nodejs/main.js index cedec00..f1197ea 100644 --- a/src/nodejs/main.js +++ b/src/nodejs/main.js @@ -1,16 +1,13 @@ var clutch = require('clutch'); var http = require('http'); +var fs = require('fs'); var pg = require('pg'); var xmlGenerator = require('./xmlGenerator.js'); var opts = require('opts'); -var config = require('./config.json'); var osmRes = require('./response'); var log4js = require('log4js')(); var log = log4js.getLogger('global'); - - - - +var config; // #################### MAY be put to different module later @@ -43,7 +40,7 @@ function rowToNode(row){ 'version': row.version, 'changeset': row.changeset_id, 'lat' : row.lat, - 'lon' : row.lon, + 'lon' : row.lon }; if(row.tags != '{}') { @@ -83,25 +80,14 @@ function rowToWay(row){ // #################### MAY be put to different module later -function loadCustomConfig(path) { - log.info("reading custom config: " + path); - if( path[0] != '/'){ - path = __dirname + '/' + path; - } - log.info(path); - config = require(path); -} - var options = [ - { short : 'c' , - long : 'config' , - description : 'Select configuration file' , - value : true , - callback : function(value) { loadCustomConfig(value); } + { short : 'c', + long : 'config', + description : 'Select configuration file', + value : true } ]; - function createWayBboxQuery(key, value, left, bottom, right, top) { return { text: 'SELECT id,tstamp,version,changeset_id,nodes,user_id,hstore_to_array(tags) as tags ' + @@ -254,8 +240,28 @@ myRoutes = clutch.route404([ //['GET /api/relation\\[(\\w+)=(\\w+)\\](\\[bbox=(\\d),(\\d),(\\d),(\\d)\\])$',relationBboxHandler], ]); -log.setLevel(config.logLevel); -log.info("server starting..."); +function getConfig(configPath, callback) { + if( configPath[0] != '/'){ + configPath = __dirname + '/' + configPath; + } + fs.readFile(configPath, function(err, data) { + if (err) { + throw err; + } + callback(JSON.parse(data)); + }); +} + +function init(newConfig) { + config = newConfig; + log.setLevel(config.logLevel); + log.info("server starting..."); + log.info("loaded config from " + configPath); + http.createServer(myRoutes).listen(config.port, config.host); + log.info("Started server at " + config.host + ":" + config.port ); +} + opts.parse(options, true); -http.createServer(myRoutes).listen(config.port, config.host); -log.info("Started server at " + config.host + ":" + config.port ); +configPath = opts.get('config') || "config.json"; +console.log("loading config " + configPath); +config = getConfig(configPath, init); diff --git a/src/nodejs/xmlGenerator.js b/src/nodejs/xmlGenerator.js index 5846717..258cb18 100644 --- a/src/nodejs/xmlGenerator.js +++ b/src/nodejs/xmlGenerator.js @@ -1,12 +1,10 @@ -var config = require('./config.json'); - var builder = require('xmlbuilder'); //set up logger var log4js = require('log4js')(); //note the need to call the function //log4js.addAppender(log4js.fileAppender('osm-xapi.log'), 'cheese'); var log = log4js.getLogger('xmlGenerator'); -log.setLevel(config.logLevel); +// TODO how to get log level from main's config? exports.createNode = function (node) { log.debug(node); |