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:
committed by
Facebook GitHub Bot
parent
0f9eeda2dd
commit
a96caacb2b
@@ -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*/
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user