diff --git a/package-lock.json b/package-lock.json index 6ef5b02..de2ab25 100644 --- a/package-lock.json +++ b/package-lock.json @@ -67,6 +67,7 @@ "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", "integrity": "sha1-DNkKVhCT810KmSVsIrcGlDP60Rc=", "dev": true, + "optional": true, "requires": { "kind-of": "^3.0.2", "longest": "^1.0.1", @@ -462,6 +463,15 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, + "cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "requires": { + "object-assign": "^4", + "vary": "^1" + } + }, "currently-unhandled": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/currently-unhandled/-/currently-unhandled-0.4.1.tgz", @@ -1274,7 +1284,8 @@ "version": "1.1.6", "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", - "dev": true + "dev": true, + "optional": true }, "is-builtin-module": { "version": "1.0.0", @@ -1453,6 +1464,7 @@ "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", "dev": true, + "optional": true, "requires": { "is-buffer": "^1.1.5" } @@ -1495,7 +1507,8 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", "integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=", - "dev": true + "dev": true, + "optional": true }, "loud-rejection": { "version": "1.6.0", @@ -5199,7 +5212,8 @@ "version": "1.6.1", "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=", - "dev": true + "dev": true, + "optional": true }, "repeating": { "version": "2.0.1", diff --git a/package.json b/package.json index 0f51489..ccea860 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "start": "node server" }, "dependencies": { + "cors": "^2.8.5", "dotenv": "^6.0.0", "express": "^4.16.3", "geo-tz": "^4.0.1", diff --git a/routes/weather.js b/routes/weather.js index aa8737d..275d63a 100755 --- a/routes/weather.js +++ b/routes/weather.js @@ -76,6 +76,9 @@ function getOWMWeatherData( location, callback ) { weather.wind = weather.wind / maxCount; weather.precip = weather.precip / maxCount; weather.icon = data.list[0].weather[0].icon; + weather.region = data.city.country; + weather.city = data.city.name; + weather.description = data.list[0].weather[0].description; location = location.join( "," ); @@ -196,7 +199,10 @@ exports.showWeatherData = function( req, res ) { location = [ parseFloat( location[ 0 ] ), parseFloat( location[ 1 ] ) ]; // Continue with the weather request - getOWMWeatherData( location, function( data ) { res.json( data ); } ); + getOWMWeatherData( location, function( data ) { + data.location = location; + res.json( data ); + } ); } else { // Attempt to resolve provided location to GPS coordinates when it does not match @@ -208,7 +214,10 @@ exports.showWeatherData = function( req, res ) { } location = result; - getOWMWeatherData( location, function( data ) { res.json( data ); } ); + getOWMWeatherData( location, function( data ) { + data.location = location; + res.json( data ); + } ); } ); } }; diff --git a/server.js b/server.js index 3ea2e4b..b229d8d 100755 --- a/server.js +++ b/server.js @@ -1,5 +1,6 @@ var express = require( "express" ), - weather = require( "./routes/weather.js" ), + weather = require( "./routes/weather.js" ), + cors = require( "cors" ), host = process.env.HOST || "127.0.0.1", port = process.env.PORT || 3000, app = express(); @@ -17,7 +18,7 @@ app.get( /weather(\d+)\.py/, weather.getWeather ); app.get( /(\d+)/, weather.getWeather ); // Handle requests matching /weatherData -app.get( /weatherData/, weather.showWeatherData ); +app.get( /weatherData/, cors(), weather.showWeatherData ); app.get( "/", function( req, res ) { res.send( "OpenSprinkler Weather Service" );