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 =
|
const execPath =
|
||||||
process.execPath || (await electronIpcClient.send('getProcess')).execPath;
|
process.execPath || (await electronIpcClient.send('getProcess')).execPath;
|
||||||
const appPath = await electronIpcClient.send('getPath', 'app');
|
const appPath = await electronIpcClient.send('getPath', 'app');
|
||||||
const staticPath = getStaticDir(appPath);
|
const staticPath = getStaticPath(appPath);
|
||||||
const isProduction = !/node_modules[\\/]electron[\\/]/.test(execPath);
|
const isProduction = !/node_modules[\\/]electron[\\/]/.test(execPath);
|
||||||
const env = process.env;
|
const env = process.env;
|
||||||
const environmentInfo = await getEnvironmentInfo(
|
const environmentInfo = await getEnvironmentInfo(
|
||||||
@@ -169,7 +169,7 @@ async function getFlipperServer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const {readyForIncomingConnections} = await startServer({
|
const {readyForIncomingConnections} = await startServer({
|
||||||
staticDir: staticPath,
|
staticPath,
|
||||||
entry: 'index.web.dev.html',
|
entry: 'index.web.dev.html',
|
||||||
tcp: false,
|
tcp: false,
|
||||||
port,
|
port,
|
||||||
@@ -182,7 +182,7 @@ async function getFlipperServer(
|
|||||||
false,
|
false,
|
||||||
keytar,
|
keytar,
|
||||||
'embedded',
|
'embedded',
|
||||||
environmentInfo.isHeadlessBuild,
|
environmentInfo,
|
||||||
);
|
);
|
||||||
|
|
||||||
const companionEnv = await initCompanionEnv(server);
|
const companionEnv = await initCompanionEnv(server);
|
||||||
@@ -235,7 +235,7 @@ start().catch((e) => {
|
|||||||
'Failed to start Flipper desktop: ' + e;
|
'Failed to start Flipper desktop: ' + e;
|
||||||
});
|
});
|
||||||
|
|
||||||
function getStaticDir(appPath: string) {
|
function getStaticPath(appPath: string) {
|
||||||
let _staticPath = path.resolve(__dirname, '..', '..', 'static');
|
let _staticPath = path.resolve(__dirname, '..', '..', 'static');
|
||||||
// fs.existSync used here, as fs-extra doesn't resovle properly in the app.asar
|
// fs.existSync used here, as fs-extra doesn't resovle properly in the app.asar
|
||||||
/* eslint-disable node/no-sync*/
|
/* eslint-disable node/no-sync*/
|
||||||
|
|||||||
@@ -12,12 +12,12 @@ import {
|
|||||||
parseEnvironmentVariables,
|
parseEnvironmentVariables,
|
||||||
getLogger,
|
getLogger,
|
||||||
FlipperServerType,
|
FlipperServerType,
|
||||||
|
EnvironmentInfo,
|
||||||
} from 'flipper-common';
|
} from 'flipper-common';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import {KeytarModule} from '../utils/keytar';
|
import {KeytarModule} from '../utils/keytar';
|
||||||
import {FlipperServerImpl} from '../FlipperServerImpl';
|
import {FlipperServerImpl} from '../FlipperServerImpl';
|
||||||
import {getEnvironmentInfo} from '../utils/environmentInfo';
|
|
||||||
import {getGatekeepers} from '../gk';
|
import {getGatekeepers} from '../gk';
|
||||||
import {loadLauncherSettings} from '../utils/launcherSettings';
|
import {loadLauncherSettings} from '../utils/launcherSettings';
|
||||||
import {loadProcessConfig} from '../utils/processConfig';
|
import {loadProcessConfig} from '../utils/processConfig';
|
||||||
@@ -26,25 +26,23 @@ import {loadSettings} from '../utils/settings';
|
|||||||
/**
|
/**
|
||||||
* Creates an instance of FlipperServer (FlipperServerImpl). This is the
|
* Creates an instance of FlipperServer (FlipperServerImpl). This is the
|
||||||
* server used by clients to connect to.
|
* server used by clients to connect to.
|
||||||
* @param rootDir Application path.
|
* @param rootPath Application path.
|
||||||
* @param staticPath Static assets path.
|
* @param staticPath Static assets path.
|
||||||
* @param settingsString Optional settings used to override defaults.
|
* @param settingsString Optional settings used to override defaults.
|
||||||
* @param enableLauncherSettings Optional launcher settings used to override defaults.
|
* @param enableLauncherSettings Optional launcher settings used to override defaults.
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function startFlipperServer(
|
export async function startFlipperServer(
|
||||||
rootDir: string,
|
rootPath: string,
|
||||||
staticPath: string,
|
staticPath: string,
|
||||||
settingsString: string,
|
settingsString: string,
|
||||||
enableLauncherSettings: boolean,
|
enableLauncherSettings: boolean,
|
||||||
keytarModule: KeytarModule,
|
keytarModule: KeytarModule,
|
||||||
type: FlipperServerType,
|
type: FlipperServerType,
|
||||||
isHeadless: boolean,
|
environmentInfo: EnvironmentInfo,
|
||||||
): Promise<FlipperServerImpl> {
|
): Promise<FlipperServerImpl> {
|
||||||
const execPath = process.execPath;
|
const execPath = process.execPath;
|
||||||
const appPath = rootDir;
|
const appPath = rootPath;
|
||||||
const isProduction =
|
|
||||||
process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== 'test';
|
|
||||||
const env = process.env;
|
const env = process.env;
|
||||||
let desktopPath = path.resolve(os.homedir(), 'Desktop');
|
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');
|
console.warn('Failed to find desktop path, falling back to homedir');
|
||||||
desktopPath = os.homedir();
|
desktopPath = os.homedir();
|
||||||
}
|
}
|
||||||
|
|
||||||
const environmentInfo = await getEnvironmentInfo(
|
|
||||||
appPath,
|
|
||||||
isProduction,
|
|
||||||
isHeadless,
|
|
||||||
);
|
|
||||||
|
|
||||||
return new FlipperServerImpl(
|
return new FlipperServerImpl(
|
||||||
{
|
{
|
||||||
environmentInfo,
|
environmentInfo,
|
||||||
env: parseEnvironmentVariables(process.env),
|
env: parseEnvironmentVariables(process.env),
|
||||||
// TODO: make username parameterizable
|
|
||||||
gatekeepers: getGatekeepers(environmentInfo.os.unixname),
|
gatekeepers: getGatekeepers(environmentInfo.os.unixname),
|
||||||
paths: {
|
paths: {
|
||||||
appPath,
|
appPath,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import {validateAuthToken} from '../utils/certificateUtils';
|
|||||||
|
|
||||||
type Config = {
|
type Config = {
|
||||||
port: number;
|
port: number;
|
||||||
staticDir: string;
|
staticPath: string;
|
||||||
entry: string;
|
entry: string;
|
||||||
tcp: boolean;
|
tcp: boolean;
|
||||||
};
|
};
|
||||||
@@ -99,7 +99,7 @@ async function startHTTPServer(config: Config): Promise<{
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get('/', (_req, res) => {
|
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);
|
res.end(content);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -108,7 +108,7 @@ async function startHTTPServer(config: Config): Promise<{
|
|||||||
res.end('flipper-ok');
|
res.end('flipper-ok');
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use(express.static(config.staticDir));
|
app.use(express.static(config.staticPath));
|
||||||
|
|
||||||
return startProxyServer(config, app);
|
return startProxyServer(config, app);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,11 @@ import fs from 'fs-extra';
|
|||||||
import yargs from 'yargs';
|
import yargs from 'yargs';
|
||||||
import open from 'open';
|
import open from 'open';
|
||||||
import {initCompanionEnv} from 'flipper-server-companion';
|
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 {isTest} from 'flipper-common';
|
||||||
import exitHook from 'exit-hook';
|
import exitHook from 'exit-hook';
|
||||||
import {getAuthToken} from 'flipper-server-core';
|
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, '..', '..')
|
||||||
: path.resolve(__dirname, '..'); // in pre packaged versions of the server, static is copied inside the package
|
: 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() {
|
async function start() {
|
||||||
const enhanceLogger = await initializeLogger(staticDir);
|
const enhanceLogger = await initializeLogger(staticPath);
|
||||||
|
|
||||||
let keytar: any = undefined;
|
let keytar: any = undefined;
|
||||||
try {
|
try {
|
||||||
if (!isTest()) {
|
if (!isTest()) {
|
||||||
const keytarPath = path.join(
|
const keytarPath = path.join(
|
||||||
staticDir,
|
staticPath,
|
||||||
'native-modules',
|
'native-modules',
|
||||||
`keytar-${process.platform}-${process.arch}.node`,
|
`keytar-${process.platform}-${process.arch}.node`,
|
||||||
);
|
);
|
||||||
@@ -104,20 +108,29 @@ async function start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const {app, server, socket, readyForIncomingConnections} = await startServer({
|
const {app, server, socket, readyForIncomingConnections} = await startServer({
|
||||||
staticDir,
|
staticPath,
|
||||||
entry: `index.web${argv.bundler ? '.dev' : ''}.html`,
|
entry: `index.web${argv.bundler ? '.dev' : ''}.html`,
|
||||||
port: argv.port,
|
port: argv.port,
|
||||||
tcp: argv.tcp,
|
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(
|
const flipperServer = await startFlipperServer(
|
||||||
rootDir,
|
rootPath,
|
||||||
staticDir,
|
staticPath,
|
||||||
argv.settingsString,
|
argv.settingsString,
|
||||||
argv.launcherSettings,
|
argv.launcherSettings,
|
||||||
keytar,
|
keytar,
|
||||||
'external',
|
'external',
|
||||||
true,
|
environmentInfo,
|
||||||
);
|
);
|
||||||
|
|
||||||
exitHook(async () => {
|
exitHook(async () => {
|
||||||
@@ -142,7 +155,7 @@ async function start() {
|
|||||||
await flipperServer.connect();
|
await flipperServer.connect();
|
||||||
|
|
||||||
if (argv.bundler) {
|
if (argv.bundler) {
|
||||||
await attachDevServer(app, server, socket, rootDir);
|
await attachDevServer(app, server, socket, rootPath);
|
||||||
}
|
}
|
||||||
await readyForIncomingConnections(flipperServer, companionEnv);
|
await readyForIncomingConnections(flipperServer, companionEnv);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user