@@ -20,7 +20,8 @@ const config = {
2020 buildVersion : Date . now ( ) . toString ( ) ,
2121 publish : ! ! process . env . PUBLISH ,
2222 isRelease : process . env . NODE_ENV === 'production' ,
23- isStaticInstall : packageJson . config . installed ,
23+ browserBackendHost : packageJson . config . browserBackendHost || 'ws://localhost:12001/' ,
24+ isBrowserBackendRemote : ! ! packageJson . config . isBrowserBackendRemote ,
2425 static : {
2526 src : './static' ,
2627 dest : './build' ,
@@ -340,7 +341,7 @@ function configVersion(done) {
340341
341342/* ----- Version ---- */
342343
343- function createVersionFile ( done ) {
344+ function updateConstants ( done ) {
344345 // Get the current date
345346 const currentDate = new Date ( ) ;
346347
@@ -362,6 +363,22 @@ function createVersionFile(done) {
362363 const data = `export const VERSION = '${ formattedDate } (${ gitCommitHash } )';
363364export const VERSION_EPOCH = ${ Date . now ( ) } ;
364365export const FPA_VERSION = '${ fpaVersion } ';
366+ export const IS_BROWSER_BACKEND_REMOTE = ${ config . isBrowserBackendRemote } ;
367+ export const BROWSER_ISDEV = ${ ! config . isRelease } ;
368+ export const getBrowserBackendHost = () => {
369+ const host = '${ config . browserBackendHost } ';
370+ if (host.startsWith('ws:') || host.startsWith('wss:/')) {
371+ return host;
372+ } else {
373+ // Convert relative path to absolute WebSocket URL
374+ const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
375+ const hostname = window.location.hostname;
376+ const port = window.location.port;
377+ const portSuffix = port ? ':' + port : '';
378+ const basePath = host.startsWith('/') ? host : '/' + host;
379+ return protocol + '//' + hostname + portSuffix + basePath;
380+ }
381+ };
365382` ;
366383
367384 // Write to src/shared/version.ts
@@ -483,7 +500,7 @@ async function extractTarball(inputFilePath, outputDirectory) {
483500export const clean = series ( cleanTask ) ;
484501export const build = series (
485502 cleanTask ,
486- createVersionFile ,
503+ updateConstants ,
487504 installCrossDeps ,
488505 buildStatic ,
489506 parallel (
@@ -497,7 +514,7 @@ export const build = series(
497514) ;
498515export const watch = series (
499516 cleanTask ,
500- createVersionFile ,
517+ updateConstants ,
501518 installCrossDeps ,
502519 buildStatic ,
503520 parallel (
@@ -511,7 +528,7 @@ export const watch = series(
511528) ;
512529export const watchStatic = series (
513530 cleanTask ,
514- createVersionFile ,
531+ updateConstants ,
515532 installCrossDeps ,
516533 buildStatic ,
517534 buildExtensions ,
0 commit comments