Expose info endpoint

Summary:
Expose an endpoint to retrieve server environment information.

We can use version information and process number to aid engineers with troubleshooting Flipper.

Reviewed By: antonk52

Differential Revision: D49537325

fbshipit-source-id: 511fe4441638f91cd35f13706ceeeb515051416b
This commit is contained in:
Lorenzo Blasa
2023-09-22 08:17:48 -07:00
committed by Facebook GitHub Bot
parent db07297e2d
commit bdf5065f10
3 changed files with 31 additions and 13 deletions

View File

@@ -20,6 +20,7 @@ import {FlipperServerImpl} from '../FlipperServerImpl';
import {FlipperServerCompanionEnv} from 'flipper-server-companion';
import {validateAuthToken} from '../app-connectivity/certificate-exchange/certificate-utils';
import {tracker} from '../tracker';
import {EnvironmentInfo} from 'flipper-common';
type Config = {
port: number;
@@ -89,13 +90,16 @@ let isReadyWaitable: Promise<void> | undefined;
* @param config Server configuration.
* @returns Returns a promise to the created server, proxy and WS server.
*/
export async function startServer(config: Config): Promise<{
export async function startServer(
config: Config,
environmentInfo: EnvironmentInfo,
): Promise<{
app: Express;
server: http.Server;
socket: WebSocketServer;
readyForIncomingConnections: ReadyForConnections;
}> {
return await startHTTPServer(config);
return await startHTTPServer(config, environmentInfo);
}
/**
@@ -104,7 +108,10 @@ export async function startServer(config: Config): Promise<{
* @param config Server configuration.
* @returns A promise to both app and HTTP server.
*/
async function startHTTPServer(config: Config): Promise<{
async function startHTTPServer(
config: Config,
environmentInfo: EnvironmentInfo,
): Promise<{
app: Express;
server: http.Server;
socket: WebSocketServer;
@@ -133,6 +140,11 @@ async function startHTTPServer(config: Config): Promise<{
res.end(JSON.stringify({isReady}));
});
app.get('/info', (_req, res) => {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(environmentInfo));
});
app.get('/shutdown', (_req, res) => {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({success: true}));