aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app.js11
-rw-r--r--routes/index.js8
2 files changed, 18 insertions, 1 deletions
diff --git a/app.js b/app.js
index f7dea78..f6565a1 100644
--- a/app.js
+++ b/app.js
@@ -6,6 +6,13 @@ var accept = require('http-accept')
var app = express();
+var database_url = process.env.DATABASE_URL;
+
+if(typeof database_url != 'string' || database_url.length == 0) {
+ console.warn('Missing environment property DATABASE_URL');
+ process.exit(1);
+}
+
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
@@ -21,6 +28,10 @@ app.configure(function(){
app.use(accept);
app.use(app.router);
app.use(express.static(__dirname + '/public', {maxAge: 60 * 60 * 1000}));
+
+ routes.setup({
+ database_url: process.env.DATABASE_URL
+ });
});
app.configure('development', function(){
diff --git a/routes/index.js b/routes/index.js
index 30f0f9b..24ddf9f 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -4,6 +4,12 @@ var collection_json = require('collection_json')
, EmployeeDao = require('../lib/dao.js')
, _ = require('underscore');
+var database_url;
+
+module.exports.setup = function(options) {
+ database_url = options.database_url;
+}
+
function mapRow(row) {
var data = _.map(row, function(value, key) {
return {name: key, value: value};
@@ -50,7 +56,7 @@ function pager(req) {
}
function connect(res, cb) {
- pg.connect(process.env.DATABASE_URL, function(err, client) {
+ pg.connect(database_url, function(err, client) {
if(err) {
res.send('Unable to connect to PostgreSQL.', {'Content-Type': 'text/plain'}, 500);
}