mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Return new apiTarget with long timeout for watch requests
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
parent
ff042d8c1f
commit
8c0538fec1
@ -1,22 +0,0 @@
|
|||||||
diff --git a/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js b/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js
|
|
||||||
index 995a0db..a5c37f5 100644
|
|
||||||
--- a/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js
|
|
||||||
+++ b/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js
|
|
||||||
@@ -50,7 +50,7 @@ module.exports = {
|
|
||||||
*/
|
|
||||||
|
|
||||||
timeout: function timeout(req, res, options) {
|
|
||||||
- if(options.timeout) {
|
|
||||||
+ if(options.timeout || options.timeout === 0) {
|
|
||||||
req.socket.setTimeout(options.timeout);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
@@ -134,7 +134,7 @@ module.exports = {
|
|
||||||
|
|
||||||
// allow outgoing socket to timeout so that we could
|
|
||||||
// show an error page at the initial request
|
|
||||||
- if(options.proxyTimeout) {
|
|
||||||
+ if(options.proxyTimeout || options.proxyTimeout === 0) {
|
|
||||||
proxyReq.setTimeout(options.proxyTimeout, function() {
|
|
||||||
proxyReq.abort();
|
|
||||||
});
|
|
||||||
@ -102,13 +102,20 @@ export class ContextHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getApiTarget(timeout: number) {
|
public async getApiTarget(isWatchRequest = false) {
|
||||||
if (this.apiTarget) {
|
if (this.apiTarget && !isWatchRequest) {
|
||||||
this.apiTarget.timeout = timeout
|
|
||||||
return this.apiTarget
|
return this.apiTarget
|
||||||
}
|
}
|
||||||
|
const timeout = isWatchRequest ? 4 * 60 * 60 * 1000 : 30000 // 4 hours for watch request, 30 seconds for the rest
|
||||||
|
const apiTarget = await this.newApiTarget(timeout)
|
||||||
|
if (!isWatchRequest) {
|
||||||
|
this.apiTarget = apiTarget
|
||||||
|
}
|
||||||
|
return apiTarget
|
||||||
|
}
|
||||||
|
|
||||||
this.apiTarget = {
|
protected async newApiTarget(timeout: number) {
|
||||||
|
return {
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
headers: {
|
headers: {
|
||||||
@ -121,8 +128,6 @@ export class ContextHandler {
|
|||||||
path: this.clusterUrl.path
|
path: this.clusterUrl.path
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.apiTarget
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async resolveProxyPort(): Promise<number> {
|
protected async resolveProxyPort(): Promise<number> {
|
||||||
|
|||||||
@ -130,8 +130,8 @@ export class LensProxy {
|
|||||||
if (req.url.startsWith("/api-kube/")) {
|
if (req.url.startsWith("/api-kube/")) {
|
||||||
delete req.headers.authorization
|
delete req.headers.authorization
|
||||||
req.url = req.url.replace("/api-kube", "")
|
req.url = req.url.replace("/api-kube", "")
|
||||||
const timeout = req.url.includes("watch=") ? 0 : 30000
|
const isWatchRequest = req.url.includes("watch=")
|
||||||
return await contextHandler.getApiTarget(timeout)
|
return await contextHandler.getApiTarget(isWatchRequest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user