Rebase on master
This commit is contained in:
33
server.ts
33
server.ts
@@ -1,14 +1,19 @@
|
||||
var express = require( "express" ),
|
||||
weather = require( "./routes/weather.js" ),
|
||||
cors = require( "cors" ),
|
||||
host = process.env.HOST || "127.0.0.1",
|
||||
port = process.env.PORT || 3000,
|
||||
app = express();
|
||||
const packageJson = require( "../package.json" ),
|
||||
express = require( "express" ),
|
||||
weather = require( "./routes/weather.js" ),
|
||||
local = require( "./routes/local.js" ),
|
||||
cors = require( "cors" );
|
||||
|
||||
if ( !process.env.HOST || !process.env.PORT ) {
|
||||
let host = process.env.HOST || "127.0.0.1",
|
||||
port = process.env.PORT || 3000,
|
||||
pws = process.env.PWS || "none",
|
||||
app = express();
|
||||
|
||||
if ( !process.env.HOST || !process.env.PORT || !process.env.LOCAL_PWS ) {
|
||||
require( "dotenv" ).load();
|
||||
host = process.env.HOST || host;
|
||||
port = process.env.PORT || port;
|
||||
pws = process.env.PWS || pws;
|
||||
}
|
||||
|
||||
// Handle requests matching /weatherID.py where ID corresponds to the
|
||||
@@ -21,8 +26,13 @@ app.get( /(\d+)/, weather.getWateringData );
|
||||
app.options( /weatherData/, cors() );
|
||||
app.get( /weatherData/, cors(), weather.getWeatherData );
|
||||
|
||||
// Endpoint to stream Weather Underground data from local PWS
|
||||
if ( pws === "WU" ) {
|
||||
app.get( "/weatherstation/updateweatherstation.php", local.captureWUStream );
|
||||
}
|
||||
|
||||
app.get( "/", function( req, res ) {
|
||||
res.send( "OpenSprinkler Weather Service" );
|
||||
res.send( packageJson.description + " v" + packageJson.version );
|
||||
} );
|
||||
|
||||
// Handle 404 error
|
||||
@@ -33,7 +43,12 @@ app.use( function( req, res ) {
|
||||
|
||||
// Start listening on the service port
|
||||
app.listen( port, host, function() {
|
||||
console.log( "OpenSprinkler Weather Service now listening on %s:%s", host, port );
|
||||
console.log( "%s now listening on %s:%s", packageJson.description, host, port );
|
||||
|
||||
if (pws !== "none" ) {
|
||||
console.log( "%s now listening for local weather stream", packageJson.description );
|
||||
}
|
||||
} );
|
||||
|
||||
exports.app = app;
|
||||
exports.pws = pws;
|
||||
|
||||
Reference in New Issue
Block a user