mirror of
https://github.com/TheBinaryNinja/tvapp2.git
synced 2026-06-04 03:55:41 -04:00
feat: add env variable WEB_PROXY_HEADER to override proxy header
This commit is contained in:
@@ -74,6 +74,7 @@ ENV URL_REPO="https://git.binaryninja.net/binaryninja/"
|
|||||||
ENV WEB_IP="0.0.0.0"
|
ENV WEB_IP="0.0.0.0"
|
||||||
ENV WEB_PORT=4124
|
ENV WEB_PORT=4124
|
||||||
ENV WEB_ENCODING="deflate, br"
|
ENV WEB_ENCODING="deflate, br"
|
||||||
|
ENV WEB_PROXY_HEADER="x-forwarded-for"
|
||||||
ENV STREAM_QUALITY="hd"
|
ENV STREAM_QUALITY="hd"
|
||||||
ENV FILE_URL="urls.txt"
|
ENV FILE_URL="urls.txt"
|
||||||
ENV FILE_M3U="playlist.m3u8"
|
ENV FILE_M3U="playlist.m3u8"
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ const envApiKey = process.env.API_KEY || null;
|
|||||||
const envWebIP = process.env.WEB_IP || '0.0.0.0';
|
const envWebIP = process.env.WEB_IP || '0.0.0.0';
|
||||||
const envWebPort = process.env.WEB_PORT || `4124`;
|
const envWebPort = process.env.WEB_PORT || `4124`;
|
||||||
const envWebEncoding = process.env.WEB_ENCODING || 'deflate, br';
|
const envWebEncoding = process.env.WEB_ENCODING || 'deflate, br';
|
||||||
|
const envProxyHeader = process.env.WEB_PROXY_HEADER || 'x-forwarded-for';
|
||||||
const envHealthTimer = process.env.HEALTH_TIMER || 600000;
|
const envHealthTimer = process.env.HEALTH_TIMER || 600000;
|
||||||
const LOG_LEVEL = process.env.LOG_LEVEL || 10;
|
const LOG_LEVEL = process.env.LOG_LEVEL || 10;
|
||||||
|
|
||||||
@@ -235,6 +236,23 @@ else
|
|||||||
FILE_GZP = path.resolve( __dirname, FOLDER_WWW, `${ envFileGZP }` );
|
FILE_GZP = path.resolve( __dirname, FOLDER_WWW, `${ envFileGZP }` );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Get Client IP
|
||||||
|
|
||||||
|
prioritize header.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const clientIp = ( req ) =>
|
||||||
|
( req.headers && (
|
||||||
|
req.headers[envProxyHeader]?.split( ',' )?.shift() ||
|
||||||
|
req.headers['X-Forwarded-For']?.split( ',' )?.shift() ||
|
||||||
|
req.headers['x-forwarded-for']?.split( ',' )?.shift() ||
|
||||||
|
req.headers['cf-connecting-ip']?.split( ',' )?.shift() ||
|
||||||
|
req.headers['x-real-ip']?.split( ',' )?.shift() ||
|
||||||
|
req.headers['X-Real-IP']?.split( ',' )?.shift() ||
|
||||||
|
req.socket?.remoteAddress ) ||
|
||||||
|
envIpContainer );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Semaphore > Declare
|
Semaphore > Declare
|
||||||
|
|
||||||
@@ -574,7 +592,7 @@ async function serveKey( req, res )
|
|||||||
{
|
{
|
||||||
ip: envIpContainer,
|
ip: envIpContainer,
|
||||||
gateway: envIpGateway,
|
gateway: envIpGateway,
|
||||||
uptime: process.uptime(),
|
client: clientIp( req ),
|
||||||
message: 'Error: Missing "uri" parameter for key download.',
|
message: 'Error: Missing "uri" parameter for key download.',
|
||||||
status: 'unhealthy',
|
status: 'unhealthy',
|
||||||
ref: req.url,
|
ref: req.url,
|
||||||
@@ -605,7 +623,7 @@ async function serveKey( req, res )
|
|||||||
{
|
{
|
||||||
ip: envIpContainer,
|
ip: envIpContainer,
|
||||||
gateway: envIpGateway,
|
gateway: envIpGateway,
|
||||||
uptime: process.uptime(),
|
client: clientIp( req ),
|
||||||
message: `Failed to serve key`,
|
message: `Failed to serve key`,
|
||||||
error: `${ err.message }`,
|
error: `${ err.message }`,
|
||||||
status: 'unhealthy',
|
status: 'unhealthy',
|
||||||
@@ -768,7 +786,7 @@ async function serveM3UPlaylist( req, res )
|
|||||||
{
|
{
|
||||||
ip: envIpContainer,
|
ip: envIpContainer,
|
||||||
gateway: envIpGateway,
|
gateway: envIpGateway,
|
||||||
uptime: process.uptime(),
|
client: clientIp( req ),
|
||||||
message: `Missing ?url= parameter`,
|
message: `Missing ?url= parameter`,
|
||||||
status: `unhealthy`,
|
status: `unhealthy`,
|
||||||
ref: req.url,
|
ref: req.url,
|
||||||
@@ -822,7 +840,7 @@ async function serveM3UPlaylist( req, res )
|
|||||||
{
|
{
|
||||||
ip: envIpContainer,
|
ip: envIpContainer,
|
||||||
gateway: envIpGateway,
|
gateway: envIpGateway,
|
||||||
uptime: process.uptime(),
|
client: clientIp( req ),
|
||||||
message: `Failed to retrieve tokenized URL.`,
|
message: `Failed to retrieve tokenized URL.`,
|
||||||
status: `unhealthy`,
|
status: `unhealthy`,
|
||||||
ref: req.url,
|
ref: req.url,
|
||||||
@@ -861,7 +879,7 @@ async function serveM3UPlaylist( req, res )
|
|||||||
{
|
{
|
||||||
ip: envIpContainer,
|
ip: envIpContainer,
|
||||||
gateway: envIpGateway,
|
gateway: envIpGateway,
|
||||||
uptime: process.uptime(),
|
client: clientIp( req ),
|
||||||
message: `Cannot process request when fetching channel playlist`,
|
message: `Cannot process request when fetching channel playlist`,
|
||||||
error: `${ err.message }`,
|
error: `${ err.message }`,
|
||||||
status: 'unhealthy',
|
status: 'unhealthy',
|
||||||
@@ -901,7 +919,7 @@ async function serveHealthCheck( req, res )
|
|||||||
{
|
{
|
||||||
ip: envIpContainer,
|
ip: envIpContainer,
|
||||||
gateway: envIpGateway,
|
gateway: envIpGateway,
|
||||||
uptime: process.uptime(),
|
client: clientIp( req ),
|
||||||
message: `healthy`,
|
message: `healthy`,
|
||||||
status: `healthy`,
|
status: `healthy`,
|
||||||
ref: req.url,
|
ref: req.url,
|
||||||
@@ -927,7 +945,7 @@ async function serveHealthCheck( req, res )
|
|||||||
{
|
{
|
||||||
ip: envIpContainer,
|
ip: envIpContainer,
|
||||||
gateway: envIpGateway,
|
gateway: envIpGateway,
|
||||||
uptime: process.uptime(),
|
client: clientIp( req ),
|
||||||
message: `health check failed`,
|
message: `health check failed`,
|
||||||
error: `${ err.message }`,
|
error: `${ err.message }`,
|
||||||
status: `unhealthy`,
|
status: `unhealthy`,
|
||||||
@@ -1016,7 +1034,7 @@ async function serveM3U( res, req )
|
|||||||
{
|
{
|
||||||
ip: envIpContainer,
|
ip: envIpContainer,
|
||||||
gateway: envIpGateway,
|
gateway: envIpGateway,
|
||||||
uptime: process.uptime(),
|
client: clientIp( req ),
|
||||||
message: `Fatal error serving playlist`,
|
message: `Fatal error serving playlist`,
|
||||||
error: `${ err.message }`,
|
error: `${ err.message }`,
|
||||||
status: 'unhealthy',
|
status: 'unhealthy',
|
||||||
@@ -1232,7 +1250,7 @@ const server = http.createServer( ( request, response ) =>
|
|||||||
{
|
{
|
||||||
ip: envIpContainer,
|
ip: envIpContainer,
|
||||||
gateway: envIpGateway,
|
gateway: envIpGateway,
|
||||||
uptime: process.uptime(),
|
client: clientIp( response ),
|
||||||
message: 'Restart command received',
|
message: 'Restart command received',
|
||||||
status: 'ok',
|
status: 'ok',
|
||||||
ref: request.url,
|
ref: request.url,
|
||||||
@@ -1378,7 +1396,7 @@ const server = http.createServer( ( request, response ) =>
|
|||||||
{
|
{
|
||||||
ip: envIpContainer,
|
ip: envIpContainer,
|
||||||
gateway: envIpGateway,
|
gateway: envIpGateway,
|
||||||
uptime: process.uptime(),
|
client: clientIp( response ),
|
||||||
message: 'Page not found',
|
message: 'Page not found',
|
||||||
status: 'healthy',
|
status: 'healthy',
|
||||||
ref: request.url,
|
ref: request.url,
|
||||||
|
|||||||
Reference in New Issue
Block a user