1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Close proxy server on app quit

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
Lauri Nevala 2020-06-05 10:03:15 +03:00
parent 65900e728d
commit 3999e9909a
2 changed files with 10 additions and 2 deletions

View File

@ -26,6 +26,7 @@ const promiseIpc = new PromiseIpc({ timeout: 2000 })
let windowManager: WindowManager = null; let windowManager: WindowManager = null;
let clusterManager: ClusterManager = null; let clusterManager: ClusterManager = null;
let proxyServer: proxy.LensProxy = null;
const vmURL = (isDevelopment) ? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}` : formatUrl({ const vmURL = (isDevelopment) ? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}` : formatUrl({
pathname: path.join(__dirname, "index.html"), pathname: path.join(__dirname, "index.html"),
protocol: "file", protocol: "file",
@ -57,10 +58,9 @@ async function main() {
// create cluster manager // create cluster manager
clusterManager = new ClusterManager(clusterStore.getAllClusterObjects(), port) clusterManager = new ClusterManager(clusterStore.getAllClusterObjects(), port)
// run proxy // run proxy
try { try {
proxy.listen(port, clusterManager) proxyServer = proxy.listen(port, clusterManager)
} catch (error) { } catch (error) {
logger.error(`Could not start proxy (127.0.0:${port}): ${error.message}`) logger.error(`Could not start proxy (127.0.0:${port}): ${error.message}`)
await dialog.showErrorBox("Lens Error", `Could not start proxy (127.0.0:${port}): ${error.message || "unknown error"}`) await dialog.showErrorBox("Lens Error", `Could not start proxy (127.0.0:${port}): ${error.message || "unknown error"}`)
@ -123,5 +123,6 @@ app.on("activate", () => {
app.on("will-quit", async (event) => { app.on("will-quit", async (event) => {
event.preventDefault(); // To allow mixpanel sending to be executed event.preventDefault(); // To allow mixpanel sending to be executed
if (clusterManager) clusterManager.stop() if (clusterManager) clusterManager.stop()
if (proxyServer) proxyServer.close()
app.exit(0); app.exit(0);
}) })

View File

@ -17,6 +17,7 @@ export class LensProxy {
protected clusterManager: ClusterManager protected clusterManager: ClusterManager
protected retryCounters: Map<string, number> = new Map() protected retryCounters: Map<string, number> = new Map()
protected router: Router protected router: Router
protected proxyServer: http.Server
constructor(port: number, clusterManager: ClusterManager) { constructor(port: number, clusterManager: ClusterManager) {
this.port = port this.port = port
@ -27,6 +28,12 @@ export class LensProxy {
public run() { public run() {
const proxyServer = this.buildProxyServer(); const proxyServer = this.buildProxyServer();
proxyServer.listen(this.port, "127.0.0.1") proxyServer.listen(this.port, "127.0.0.1")
this.proxyServer = proxyServer
}
public close() {
logger.info("Closing proxy server")
this.proxyServer.close()
} }
protected buildProxyServer() { protected buildProxyServer() {