mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
handle initial loading without clusters
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
1 parent
ab61fd6308
commit
10e68510c4
10 files changed
+167
-117
No files matched your search
+1
-1
@@ -39,7 +39,7 @@ export class Cluster implements ClusterModel {
|
||||
protected kubeconfigManager: KubeconfigManager;
|
||||
|
||||
public whenReady = when(() => this.initialized);
|
||||
protected disposers: CallableFunction[] = [];
|
||||
protected disposers: Function[] = [];
|
||||
|
||||
@observable initialized = false;
|
||||
@observable contextName: string;
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ async function main() {
|
||||
}
|
||||
|
||||
// create window manager and open app
|
||||
windowManager = new WindowManager();
|
||||
windowManager = new WindowManager(proxyPort);
|
||||
windowManager.showSplash();
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +126,10 @@ export class LensProxy {
|
||||
}
|
||||
|
||||
protected async handleRequest(proxy: httpProxy, req: http.IncomingMessage, res: http.ServerResponse) {
|
||||
if (req.headers.host.split(":")[0] === "no-clusters.localhost") {
|
||||
this.router.handleStaticFile(req.url, res);
|
||||
return;
|
||||
}
|
||||
const cluster = this.clusterManager.getClusterForRequest(req)
|
||||
if (!cluster) {
|
||||
const reqId = this.getRequestId(req);
|
||||
|
||||
+14
-15
@@ -52,20 +52,20 @@ export class Router {
|
||||
const matchingRoute = this.router.route(method, path);
|
||||
const routeFound = !matchingRoute.isBoom;
|
||||
if (routeFound) {
|
||||
const request = await this.getRequest({
|
||||
req, res, cluster, url,
|
||||
params: matchingRoute.params
|
||||
});
|
||||
const request = await this.getRequest({ req, res, cluster, url, params: matchingRoute.params });
|
||||
await matchingRoute.route(request)
|
||||
return true
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected async getRequest(opts: RouterRequestOpts) {
|
||||
protected async getRequest(opts: RouterRequestOpts): Promise<LensApiRequest> {
|
||||
const { req, res, url, cluster, params } = opts
|
||||
const { payload } = await Subtext.parse(req, null, { parse: true, output: 'data' });
|
||||
const request: LensApiRequest = {
|
||||
const { payload } = await Subtext.parse(req, null, {
|
||||
parse: true,
|
||||
output: "data",
|
||||
});
|
||||
return {
|
||||
cluster: cluster,
|
||||
path: url.pathname,
|
||||
raw: {
|
||||
@@ -76,7 +76,6 @@ export class Router {
|
||||
payload: payload,
|
||||
params: params
|
||||
}
|
||||
return request
|
||||
}
|
||||
|
||||
protected getMimeType(filename: string) {
|
||||
@@ -95,15 +94,15 @@ export class Router {
|
||||
return mimeTypes[path.extname(filename).slice(1)] || "text/plain"
|
||||
}
|
||||
|
||||
protected async handleStaticFile(filePath: string, response: http.ServerResponse) {
|
||||
const asset = path.resolve(outDir, filePath);
|
||||
async handleStaticFile(filePath: string, res: http.ServerResponse) {
|
||||
const asset = path.join(outDir, filePath);
|
||||
try {
|
||||
const data = await readFile(asset);
|
||||
response.setHeader("Content-Type", this.getMimeType(asset));
|
||||
response.write(data)
|
||||
response.end()
|
||||
res.setHeader("Content-Type", this.getMimeType(asset));
|
||||
res.write(data)
|
||||
res.end()
|
||||
} catch (err) {
|
||||
this.handleStaticFile(`${appName}.html`, response);
|
||||
this.handleStaticFile(`${appName}.html`, res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +110,7 @@ export class Router {
|
||||
// Static assets
|
||||
this.router.add({ method: 'get', path: '/{path*}' }, ({ params, response }: LensApiRequest) => {
|
||||
this.handleStaticFile(params.path, response);
|
||||
})
|
||||
});
|
||||
|
||||
this.router.add({ method: "get", path: `${apiPrefix}/config` }, configRoute.routeConfig.bind(configRoute))
|
||||
this.router.add({ method: "get", path: `${apiPrefix}/kubeconfig/service-account/{namespace}/{account}` }, kubeconfigRoute.routeServiceAccountRoute.bind(kubeconfigRoute))
|
||||
|
||||
+15
-15
@@ -1,4 +1,4 @@
|
||||
import { reaction } from "mobx";
|
||||
import { autorun, reaction } from "mobx";
|
||||
import { BrowserWindow, shell } from "electron"
|
||||
import windowStateKeeper from "electron-window-state"
|
||||
import type { ClusterId } from "../common/cluster-store";
|
||||
@@ -15,7 +15,7 @@ export class WindowManager {
|
||||
protected splashWindow: BrowserWindow;
|
||||
protected windowState: windowStateKeeper.State;
|
||||
|
||||
constructor() {
|
||||
constructor(protected proxyPort: number) {
|
||||
this.splashWindow = new BrowserWindow({
|
||||
width: 500,
|
||||
height: 300,
|
||||
@@ -60,22 +60,22 @@ export class WindowManager {
|
||||
this.destroyView(cluster.id);
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
// handle initial view load without clusters
|
||||
// if (!clusterStore.clusters.size) {
|
||||
// this.initNoClustersView();
|
||||
// }
|
||||
// handle no-clusters view
|
||||
autorun(() => {
|
||||
if (!clusterStore.clusters.size) {
|
||||
this.initNoClustersView();
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// fixme: first run without clusters
|
||||
// protected async initNoClustersView() {
|
||||
// const htmlView = path.join(__dirname, `${appName}.html`);
|
||||
// const view = this.initView(undefined);
|
||||
// await view.loadFile(htmlView);
|
||||
// view.show();
|
||||
// this.hideSplash();
|
||||
// }
|
||||
protected async initNoClustersView() {
|
||||
this.activeView = this.initView(undefined);
|
||||
await this.activeView.loadURL(`http://no-clusters.localhost:${this.proxyPort}`);
|
||||
this.activeView.show();
|
||||
this.hideSplash();
|
||||
}
|
||||
|
||||
async showSplash() {
|
||||
await this.splashWindow.loadURL("static://splash.html")
|
||||
|
||||
Reference in new issue
Block a user