2026-03-31 18:47:00 +03:00
|
|
|
export const runCliEntryIfMain = (dependencies) => {
|
|
|
|
|
const {
|
|
|
|
|
process,
|
|
|
|
|
currentFilename,
|
|
|
|
|
parseServeCliOptions,
|
|
|
|
|
defaultPort,
|
|
|
|
|
cloudflareProvider,
|
|
|
|
|
managedLocalMode,
|
|
|
|
|
setExitOnShutdown,
|
|
|
|
|
startServer,
|
|
|
|
|
} = dependencies;
|
|
|
|
|
|
|
|
|
|
const isCliExecution = process.argv[1] === currentFilename;
|
|
|
|
|
if (!isCliExecution) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const cliOptions = parseServeCliOptions({
|
|
|
|
|
argv: process.argv.slice(2),
|
|
|
|
|
env: process.env,
|
|
|
|
|
defaultPort,
|
|
|
|
|
cloudflareProvider,
|
|
|
|
|
managedLocalMode,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
setExitOnShutdown(true);
|
|
|
|
|
startServer({
|
|
|
|
|
port: cliOptions.port,
|
|
|
|
|
host: cliOptions.host,
|
|
|
|
|
tryCfTunnel: cliOptions.tryCfTunnel,
|
|
|
|
|
tunnelProvider: cliOptions.tunnelProvider,
|
|
|
|
|
tunnelMode: cliOptions.tunnelMode,
|
|
|
|
|
tunnelConfigPath: cliOptions.tunnelConfigPath,
|
|
|
|
|
tunnelToken: cliOptions.tunnelToken,
|
|
|
|
|
tunnelHostname: cliOptions.tunnelHostname,
|
|
|
|
|
attachSignals: true,
|
|
|
|
|
exitOnShutdown: true,
|
|
|
|
|
uiPassword: cliOptions.uiPassword,
|
2026-06-02 00:43:05 +03:00
|
|
|
apiOnly: cliOptions.apiOnly,
|
2026-03-31 18:47:00 +03:00
|
|
|
}).catch((error) => {
|
|
|
|
|
console.error('Failed to start server:', error);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
});
|
|
|
|
|
};
|