From 4c5f5294cb80afcbccf1d636e8d9142ca04ca1a3 Mon Sep 17 00:00:00 2001 From: Luke Prior <22492406+LukePrior@users.noreply.github.com> Date: Tue, 6 Apr 2021 13:41:50 +1000 Subject: [PATCH 1/7] Update index.js --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index ad4d224..5cb926d 100644 --- a/index.js +++ b/index.js @@ -32,6 +32,7 @@ const whitelist = [ "http://localhost:8080", "http://localhost:3000", "http://localhost:4000", + "http://localhost:5000", ]; const corsOptions = { From e523f1c43de03c1ef706d06a1f4e6ab295e16283 Mon Sep 17 00:00:00 2001 From: Luke Prior <22492406+LukePrior@users.noreply.github.com> Date: Tue, 6 Apr 2021 15:29:03 +1000 Subject: [PATCH 2/7] Wind at ~25km above sea level --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 5cb926d..d32c7ae 100644 --- a/index.js +++ b/index.js @@ -178,7 +178,7 @@ function getGribData(targetMoment, offset) { var_TMP: "on", }, ...wind && { - lev_10_m_above_ground: "on", + lev_20_mb: "on", var_UGRD: "on", var_VGRD: "on", }, From 22d1fee0f1897f462c9c67383e4d209413755222 Mon Sep 17 00:00:00 2001 From: Luke Prior <22492406+LukePrior@users.noreply.github.com> Date: Tue, 6 Apr 2021 15:31:36 +1000 Subject: [PATCH 3/7] 17,000m --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index d32c7ae..f3e517d 100644 --- a/index.js +++ b/index.js @@ -178,7 +178,7 @@ function getGribData(targetMoment, offset) { var_TMP: "on", }, ...wind && { - lev_20_mb: "on", + lev_70_mb: "on", var_UGRD: "on", var_VGRD: "on", }, From e97ed68f368f417fd6000a7a4b64b2bca6e6813e Mon Sep 17 00:00:00 2001 From: Luke Prior <22492406+LukePrior@users.noreply.github.com> Date: Tue, 6 Apr 2021 16:10:05 +1000 Subject: [PATCH 4/7] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index f3e517d..2a6a2cb 100644 --- a/index.js +++ b/index.js @@ -43,7 +43,7 @@ const corsOptions = { }; app.use(compression()); -app.listen(port, () => { +app.listen(port, '0.0.0.0', () => { console.log(`Running wind server for data resolution of ${resolution === "1" ? "1" : "0.5"} degree on port ${port}`); }); From 20784955a9a8190e42daee2f198f207ec11a0a28 Mon Sep 17 00:00:00 2001 From: Luke Prior <22492406+LukePrior@users.noreply.github.com> Date: Tue, 6 Apr 2021 17:29:29 +1000 Subject: [PATCH 5/7] Update index.js --- index.js | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index 2a6a2cb..d6772ac 100644 --- a/index.js +++ b/index.js @@ -26,32 +26,16 @@ const GFS_CYCLE_MAX_D = process.env.MAX_HISTORY_DAYS || 2; // Number of forecast hours to download for each model cycle const GFS_FORECAST_MAX_H = process.env.MAX_FORECAST_HOURS || 18; - -// cors config -const whitelist = [ - "http://localhost:8080", - "http://localhost:3000", - "http://localhost:4000", - "http://localhost:5000", -]; - -const corsOptions = { - origin(origin, callback) { - const originIsWhitelisted = whitelist.indexOf(origin) !== -1; - callback(null, originIsWhitelisted); - }, -}; - app.use(compression()); app.listen(port, '0.0.0.0', () => { console.log(`Running wind server for data resolution of ${resolution === "1" ? "1" : "0.5"} degree on port ${port}`); }); -app.get("/", cors(corsOptions), (req, res) => { +app.get("/", cors(), (req, res) => { res.send("Wind server : go to /latest for last wind data."); }); -app.get("/alive", cors(corsOptions), (req, res) => { +app.get("/alive", cors(), (req, res) => { res.send("Wind server is alive"); }); @@ -92,7 +76,7 @@ function findNearest(targetMoment, limitHours = GFS_FORECAST_MAX_H, searchBackwa return false; } -app.get("/latest", cors(corsOptions), (req, res, next) => { +app.get("/latest", cors(), (req, res, next) => { const targetMoment = moment().utc(); const filename = findNearest(targetMoment); if (!filename) { @@ -107,7 +91,7 @@ app.get("/latest", cors(corsOptions), (req, res, next) => { }); }); -app.get("/nearest", cors(corsOptions), (req, res, next) => { +app.get("/nearest", cors(), (req, res, next) => { const { time } = req.query; const limit = req.query.limit || GFS_FORECAST_MAX_H; From cfae4c29e0e7fa86c2b57de14a5c88d277caaf34 Mon Sep 17 00:00:00 2001 From: Luke Prior <22492406+LukePrior@users.noreply.github.com> Date: Tue, 6 Apr 2021 17:42:04 +1000 Subject: [PATCH 6/7] Update index.js --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index d6772ac..1b256a5 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,7 @@ const app = express(); const grib2json = process.env.GRIB2JSON || "./converter/bin/grib2json"; const port = process.env.PORT || 7000; const resolution = process.env.RESOLUTION || "0.5"; +const data = process.env.DATA || "lev_10_m_above_ground"; const baseDir = `https://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_${resolution === "1" ? "1p00" : "0p50"}.pl`; const wind = process.env.WIND || true; const temp = process.env.TEMP || false; @@ -162,7 +163,7 @@ function getGribData(targetMoment, offset) { var_TMP: "on", }, ...wind && { - lev_70_mb: "on", + [data]: "on", var_UGRD: "on", var_VGRD: "on", }, From ef9fb92d0bda549a5a65a73bf61082a1e6fdba1c Mon Sep 17 00:00:00 2001 From: Luke Prior <22492406+LukePrior@users.noreply.github.com> Date: Tue, 6 Apr 2021 17:51:49 +1000 Subject: [PATCH 7/7] Update README.md --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cd43f20..e6304d4 100644 --- a/README.md +++ b/README.md @@ -31,12 +31,13 @@ $ npm start The following environment variables can be used to customize behaviour: -| Variable | Description | Default | Options | -|------------|-----------------------------------------|---------|-------------| -| PORT | The port the server will listen on | 7000 | Port number | -| RESOLUTION | Requested GFS data resolution | 0.5 | 0.5, 1 | -| WIND | Enable the download of wind data | true | true, false | -| TEMP | Enable the download of temperature data | false | true, false | +| Variable | Description | Default | Options | +|------------|-----------------------------------------|-----------------------|-------------| +| PORT | The port the server will listen on | 7000 | Port number | +| RESOLUTION | Requested GFS data resolution | 0.5 | 0.5, 1 | +| WIND | Enable the download of wind data | true | true, false | +| TEMP | Enable the download of temperature data | false | true, false | +| DATA | Set Wind Data Type | lev_10_m_above_ground | data type | ## Endpoints