mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-17 05:13:32 +00:00
in cloud force port 4001 (#1575)
* force 4001 * only log if there is anything to change * skip port retry in cloud
This commit is contained in:
committed by
GitHub
parent
9d2a3d5a12
commit
ddd629d7db
@@ -4,7 +4,7 @@ import type { Server } from 'http';
|
|||||||
import { networkInterfaces } from 'os';
|
import { networkInterfaces } from 'os';
|
||||||
import type { AddressInfo } from 'net';
|
import type { AddressInfo } from 'net';
|
||||||
|
|
||||||
import { isDocker, isProduction } from '../externals.js';
|
import { isDocker, isOntimeCloud, isProduction } from '../externals.js';
|
||||||
import { logger } from '../classes/Logger.js';
|
import { logger } from '../classes/Logger.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,6 +42,10 @@ export function getNetworkInterfaces(): { name: string; address: string }[] {
|
|||||||
* @throws any other server errors will result in a throw
|
* @throws any other server errors will result in a throw
|
||||||
*/
|
*/
|
||||||
export function serverTryDesiredPort(server: Server, desiredPort: number): Promise<number> {
|
export function serverTryDesiredPort(server: Server, desiredPort: number): Promise<number> {
|
||||||
|
if (isOntimeCloud) {
|
||||||
|
return forceCloudPort(server);
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
server.once('error', (error) => {
|
server.once('error', (error) => {
|
||||||
// we should only move ports if we are in a desktop environment
|
// we should only move ports if we are in a desktop environment
|
||||||
@@ -84,6 +88,19 @@ export function serverTryDesiredPort(server: Server, desiredPort: number): Promi
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function forceCloudPort(server: Server): Promise<number> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
server.listen(4001, '0.0.0.0', () => {
|
||||||
|
const address = server.address();
|
||||||
|
if (!isAddressInfo(address)) {
|
||||||
|
reject(new Error('Unknown port type, unable to proceed'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resolve(address.port);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Guard verifies that the given address is a usable AddressInfo object
|
* Guard verifies that the given address is a usable AddressInfo object
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user