diff --git a/desktop/app/src/init.tsx b/desktop/app/src/init.tsx index 6578d06d7..96c71e6a2 100644 --- a/desktop/app/src/init.tsx +++ b/desktop/app/src/init.tsx @@ -102,7 +102,7 @@ async function getFlipperServer( const execPath = process.execPath || (await electronIpcClient.send('getProcess')).execPath; const appPath = await electronIpcClient.send('getPath', 'app'); - const staticPath = getStaticDir(appPath); + const staticPath = getStaticPath(appPath); const isProduction = !/node_modules[\\/]electron[\\/]/.test(execPath); const env = process.env; const environmentInfo = await getEnvironmentInfo( @@ -169,7 +169,7 @@ async function getFlipperServer( } const {readyForIncomingConnections} = await startServer({ - staticDir: staticPath, + staticPath, entry: 'index.web.dev.html', tcp: false, port, @@ -182,7 +182,7 @@ async function getFlipperServer( false, keytar, 'embedded', - environmentInfo.isHeadlessBuild, + environmentInfo, ); const companionEnv = await initCompanionEnv(server); @@ -235,7 +235,7 @@ start().catch((e) => { 'Failed to start Flipper desktop: ' + e; }); -function getStaticDir(appPath: string) { +function getStaticPath(appPath: string) { let _staticPath = path.resolve(__dirname, '..', '..', 'static'); // fs.existSync used here, as fs-extra doesn't resovle properly in the app.asar /* eslint-disable node/no-sync*/ diff --git a/desktop/flipper-server-core/src/server/startFlipperServer.tsx b/desktop/flipper-server-core/src/server/startFlipperServer.tsx index e687d761f..989989579 100644 --- a/desktop/flipper-server-core/src/server/startFlipperServer.tsx +++ b/desktop/flipper-server-core/src/server/startFlipperServer.tsx @@ -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 { 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, diff --git a/desktop/flipper-server-core/src/server/startServer.tsx b/desktop/flipper-server-core/src/server/startServer.tsx index cf0840763..f25222172 100644 --- a/desktop/flipper-server-core/src/server/startServer.tsx +++ b/desktop/flipper-server-core/src/server/startServer.tsx @@ -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); } diff --git a/desktop/flipper-server/src/index.tsx b/desktop/flipper-server/src/index.tsx index bd13d5f0a..5cdc13081 100644 --- a/desktop/flipper-server/src/index.tsx +++ b/desktop/flipper-server/src/index.tsx @@ -18,7 +18,11 @@ import fs from 'fs-extra'; import yargs from 'yargs'; import open from 'open'; import {initCompanionEnv} from 'flipper-server-companion'; -import {startFlipperServer, startServer} from 'flipper-server-core'; +import { + getEnvironmentInfo, + startFlipperServer, + startServer, +} from 'flipper-server-core'; import {isTest} from 'flipper-common'; import exitHook from 'exit-hook'; import {getAuthToken} from 'flipper-server-core'; @@ -76,19 +80,19 @@ console.log( }`, ); -const rootDir = argv.bundler +const rootPath = argv.bundler ? path.resolve(__dirname, '..', '..') : path.resolve(__dirname, '..'); // in pre packaged versions of the server, static is copied inside the package -const staticDir = path.join(rootDir, 'static'); +const staticPath = path.join(rootPath, 'static'); async function start() { - const enhanceLogger = await initializeLogger(staticDir); + const enhanceLogger = await initializeLogger(staticPath); let keytar: any = undefined; try { if (!isTest()) { const keytarPath = path.join( - staticDir, + staticPath, 'native-modules', `keytar-${process.platform}-${process.arch}.node`, ); @@ -104,20 +108,29 @@ async function start() { } const {app, server, socket, readyForIncomingConnections} = await startServer({ - staticDir, + staticPath, entry: `index.web${argv.bundler ? '.dev' : ''}.html`, port: argv.port, tcp: argv.tcp, }); + const isProduction = + process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== 'test'; + + const environmentInfo = await getEnvironmentInfo( + rootPath, + isProduction, + true, + ); + const flipperServer = await startFlipperServer( - rootDir, - staticDir, + rootPath, + staticPath, argv.settingsString, argv.launcherSettings, keytar, 'external', - true, + environmentInfo, ); exitHook(async () => { @@ -142,7 +155,7 @@ async function start() { await flipperServer.connect(); if (argv.bundler) { - await attachDevServer(app, server, socket, rootDir); + await attachDevServer(app, server, socket, rootPath); } await readyForIncomingConnections(flipperServer, companionEnv); }