-
Notifications
You must be signed in to change notification settings - Fork 40
/
server.ts
54 lines (42 loc) · 1.7 KB
/
server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { config as dotenv_config } from "dotenv"
dotenv_config();
import * as express from "express";
import * as cors from "cors";
import * as weather from "./routes/weather";
import * as local from "./routes/weatherProviders/local";
import * as baselineETo from "./routes/baselineETo";
import * as packageJson from "./package.json";
let host = process.env.HOST || "127.0.0.1",
port = parseInt( process.env.PORT ) || 3000;
export let pws = process.env.PWS || "none";
export const app = express();
// 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.getWateringData );
app.get( /(\d+)/, weather.getWateringData );
// Handle requests matching /weatherData
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( packageJson.description + " v" + packageJson.version );
} );
// Handle requests matching /baselineETo
app.options( /baselineETo/, cors() );
app.get( /baselineETo/, cors(), baselineETo.getBaselineETo );
// Handle 404 error
app.use( function( req, res ) {
res.status( 404 );
res.send( "Error: Request not found" );
} );
// Start listening on the service port
app.listen( port, host, function() {
console.log( "%s now listening on %s:%d", packageJson.description, host, port );
if (pws !== "none" ) {
console.log( "%s now listening for local weather stream", packageJson.description );
}
} );