2023-12-10 13:40:40 +01:00
const isFreeBSD = /^freebsd/ . test ( process . platform ) ;
2023-06-29 00:50:55 +02:00
// Interop with browser
const args = ( typeof process !== "undefined" ) ? require ( "args-parser" ) ( process . argv ) : { } ;
2021-10-15 18:57:26 +02:00
2023-12-10 13:40:40 +01:00
// If host is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available and the unspecified IPv4 address (0.0.0.0) otherwise.
// Dual-stack support for (::)
// Also read HOST if not FreeBSD, as HOST is a system environment variable in FreeBSD
let hostEnv = isFreeBSD ? null : process . env . HOST ;
const hostname = args . host || process . env . UPTIME _KUMA _HOST || hostEnv ;
const port = [ args . port , process . env . UPTIME _KUMA _PORT , process . env . PORT , 3001 ]
. map ( portValue => parseInt ( portValue ) )
. find ( portValue => ! isNaN ( portValue ) ) ;
const sslKey = args [ "ssl-key" ] || process . env . UPTIME _KUMA _SSL _KEY || process . env . SSL _KEY || undefined ;
const sslCert = args [ "ssl-cert" ] || process . env . UPTIME _KUMA _SSL _CERT || process . env . SSL _CERT || undefined ;
const sslKeyPassphrase = args [ "ssl-key-passphrase" ] || process . env . UPTIME _KUMA _SSL _KEY _PASSPHRASE || process . env . SSL _KEY _PASSPHRASE || undefined ;
const isSSL = sslKey && sslCert ;
2023-12-10 19:36:08 +01:00
/ * *
* Get the local WebSocket URL
* @ returns { string } The local WebSocket URL
* /
2023-12-10 13:40:40 +01:00
function getLocalWebSocketURL ( ) {
const protocol = isSSL ? "wss" : "ws" ;
const host = hostname || "localhost" ;
return ` ${ protocol } :// ${ host } : ${ port } ` ;
}
const localWebSocketURL = getLocalWebSocketURL ( ) ;
const demoMode = args [ "demo" ] || false ;
2022-01-04 12:21:53 +01:00
2021-10-15 18:57:26 +02:00
module . exports = {
args ,
2023-12-10 13:40:40 +01:00
hostname ,
port ,
sslKey ,
sslCert ,
sslKeyPassphrase ,
isSSL ,
localWebSocketURL ,
2022-01-04 12:21:53 +01:00
demoMode ,
2021-10-15 18:57:26 +02:00
} ;