Files
flipper/desktop/flipper-server-core/src/server/startFlipperServer.tsx
Sanjaiyan Parthipan 7cef8286f9 Concurrent Function Upgrade for Enhanced Performance (#4918)
Summary:
Republishing sanjaiyan-dev's PR https://github.com/facebook/flipper/pull/4889 running `git rebase` because of a conflict.

Pull Request resolved: https://github.com/facebook/flipper/pull/4918

Reviewed By: lblasa

Differential Revision: D47294545

Pulled By: passy

fbshipit-source-id: 74904ec6179ed5a3bab6f9b701c3cd769ecad3bf
2023-07-17 04:43:14 -07:00

82 lines
2.4 KiB
TypeScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import os from 'os';
import {
parseEnvironmentVariables,
getLogger,
FlipperServerType,
EnvironmentInfo,
} from 'flipper-common';
import path from 'path';
import fs from 'fs-extra';
import {KeytarModule} from '../utils/keytar';
import {FlipperServerImpl} from '../FlipperServerImpl';
import {getGatekeepers} from '../gk';
import {loadLauncherSettings} from '../utils/launcherSettings';
import {loadProcessConfig} from '../utils/processConfig';
import {loadSettings} from '../utils/settings';
/**
* Creates an instance of FlipperServer (FlipperServerImpl). This is the
* server used by clients to connect to.
* @param rootPath Application path.
* @param staticPath Static assets path.
* @param settingsString Optional settings used to override defaults.
* @param enableLauncherSettings Optional launcher settings used to override defaults.
* @returns
*/
export async function startFlipperServer(
rootPath: string,
staticPath: string,
settingsString: string,
enableLauncherSettings: boolean,
keytarModule: KeytarModule,
type: FlipperServerType,
environmentInfo: EnvironmentInfo,
): Promise<FlipperServerImpl> {
const execPath = process.execPath;
const appPath = rootPath;
const env = process.env;
let desktopPath = path.resolve(os.homedir(), 'Desktop');
// eslint-disable-next-line node/no-sync
if (!fs.existsSync(desktopPath)) {
console.warn('Failed to find desktop path, falling back to homedir');
desktopPath = os.homedir();
}
const [launcherSettings, settings] = await Promise.all([
loadLauncherSettings(enableLauncherSettings),
loadSettings(settingsString),
]);
return new FlipperServerImpl(
{
environmentInfo,
env: parseEnvironmentVariables(process.env),
gatekeepers: getGatekeepers(environmentInfo.os.unixname),
paths: {
appPath,
homePath: os.homedir(),
execPath,
staticPath: staticPath,
tempPath: os.tmpdir(),
desktopPath: desktopPath,
},
launcherSettings,
processConfig: loadProcessConfig(env),
settings,
validWebSocketOrigins: ['localhost:', 'http://localhost:'],
type,
},
getLogger(),
keytarModule,
);
}