EnvironmentInfo as argument to start server

Summary:
Clean initialisation by passing down the environment info to start server.

(Also rename dir to path as that's the name used in other places)

Reviewed By: passy

Differential Revision: D45731751

fbshipit-source-id: a60fdd49c567fc312d1f8da72db3a46a0828c140
This commit is contained in:
Lorenzo Blasa
2023-05-11 04:10:16 -07:00
committed by Facebook GitHub Bot
parent 0f9eeda2dd
commit a96caacb2b
4 changed files with 35 additions and 32 deletions

View File

@@ -12,12 +12,12 @@ 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 {getEnvironmentInfo} from '../utils/environmentInfo';
import {getGatekeepers} from '../gk';
import {loadLauncherSettings} from '../utils/launcherSettings';
import {loadProcessConfig} from '../utils/processConfig';
@@ -26,25 +26,23 @@ import {loadSettings} from '../utils/settings';
/**
* Creates an instance of FlipperServer (FlipperServerImpl). This is the
* server used by clients to connect to.
* @param rootDir Application path.
* @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(
rootDir: string,
rootPath: string,
staticPath: string,
settingsString: string,
enableLauncherSettings: boolean,
keytarModule: KeytarModule,
type: FlipperServerType,
isHeadless: boolean,
environmentInfo: EnvironmentInfo,
): Promise<FlipperServerImpl> {
const execPath = process.execPath;
const appPath = rootDir;
const isProduction =
process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== 'test';
const appPath = rootPath;
const env = process.env;
let desktopPath = path.resolve(os.homedir(), 'Desktop');
@@ -53,18 +51,10 @@ export async function startFlipperServer(
console.warn('Failed to find desktop path, falling back to homedir');
desktopPath = os.homedir();
}
const environmentInfo = await getEnvironmentInfo(
appPath,
isProduction,
isHeadless,
);
return new FlipperServerImpl(
{
environmentInfo,
env: parseEnvironmentVariables(process.env),
// TODO: make username parameterizable
gatekeepers: getGatekeepers(environmentInfo.os.unixname),
paths: {
appPath,

View File

@@ -27,7 +27,7 @@ import {validateAuthToken} from '../utils/certificateUtils';
type Config = {
port: number;
staticDir: string;
staticPath: string;
entry: string;
tcp: boolean;
};
@@ -99,7 +99,7 @@ async function startHTTPServer(config: Config): Promise<{
});
app.get('/', (_req, res) => {
fs.readFile(path.join(config.staticDir, config.entry), (_err, content) => {
fs.readFile(path.join(config.staticPath, config.entry), (_err, content) => {
res.end(content);
});
});
@@ -108,7 +108,7 @@ async function startHTTPServer(config: Config): Promise<{
res.end('flipper-ok');
});
app.use(express.static(config.staticDir));
app.use(express.static(config.staticPath));
return startProxyServer(config, app);
}