Files
opensprinkler-weather/server.js
2015-07-01 17:57:43 -05:00

26 lines
738 B
JavaScript

var express = require( "express" ),
weather = require( "./routes/weather.js" ),
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
app.get( /weather(\d+)\.py/, weather.getWeather );
// Handle 404 error
app.use( function( req, res ) {
res.status( 404 );
res.send( "Error: Request not found" );
} );
// Start listening on the service port
var server = app.listen( port, "127.0.0.1", function() {
console.log( "OpenSprinkler Weather Service now listening on port %s", port );
} );