From 91b429c1ddd0994dde9d6f40c08e73523b39d960 Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Wed, 1 Jul 2015 00:26:07 -0500 Subject: [PATCH] Small bug fixes --- routes/weather.js | 6 ++++-- server.js | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/routes/weather.js b/routes/weather.js index f84b754..0f89b9b 100644 --- a/routes/weather.js +++ b/routes/weather.js @@ -97,7 +97,7 @@ exports.getWeather = function( req, res ) { weatherUndergroundKey = req.query.key, outputFormat = req.query.format, firmwareVersion = req.query.fwv, - remoteAddress = req.headers[ "x-forwarded-for" ].split(",")[0] || req.connection.remoteAddress, + remoteAddress = req.headers[ "x-forwarded-for" ] || req.connection.remoteAddress, weather = {}, // After the location is resolved, this function will run to complete the weather request @@ -161,7 +161,7 @@ exports.getWeather = function( req, res ) { rh = weather.observation.imperial.rh || 0, // The absolute precipitation in the past 48 hours - precip = weather.observation.imperial.precip_2day; + precip = weather.observation.imperial.precip_2day || weather.observation.imperial.precip_24hour; if ( typeof temp !== "number" ) { @@ -218,6 +218,8 @@ exports.getWeather = function( req, res ) { return false; }; + remoteAddress = remoteAddress.split(",")[0]; + // Parse weather adjustment options try { diff --git a/server.js b/server.js index 630b117..737e350 100644 --- a/server.js +++ b/server.js @@ -3,6 +3,10 @@ var express = require( "express" ), port = process.env.PORT || 3000; app = express(); +if ( !process.env.PORT ) { + require( "dotenv" ).load(); +} + // Handle requests matching /weatherID.py where ID corresponds to the // weather adjustment method selector. // This endpoint is considered deprecated and supported for prior firmware