From 1a3f1097b3114966f691809c4e4039361ee195b3 Mon Sep 17 00:00:00 2001 From: jhwiwonc Date: Mon, 17 Apr 2023 08:25:02 -0700 Subject: [PATCH 01/25] Commit apiController and CommandLine --- package.json | 7 ++++--- server/controllers/apiController.js | 2 +- src/components/CommandLine.jsx | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index f707093..a3b9b60 100644 --- a/package.json +++ b/package.json @@ -14,16 +14,17 @@ "dependencies": { "@emotion/react": "^11.10.6", "@emotion/styled": "^11.10.6", - "@esbuild/darwin-x64": "^0.17.16", + "@esbuild/darwin-arm64": "^0.17.16", "@fontsource/roboto": "^4.5.8", "@mui/icons-material": "^5.11.16", "@mui/material": "^5.12.0", + "axios": "^1.3.5", + "bcryptjs": "^2.4.3", "concurrently": "^8.0.1", + "esbuild-darwin-arm64": "^0.15.18", "express": "^4.18.2", "mongoose": "^7.0.3", "nodemon": "^2.0.22", - "axios": "^1.3.5", - "bcryptjs": "^2.4.3", "react": "^18.2.0", "react-dom": "^18.2.0", "react-pro-sidebar": "^1.0.0", diff --git a/server/controllers/apiController.js b/server/controllers/apiController.js index eafc3c8..33247a1 100644 --- a/server/controllers/apiController.js +++ b/server/controllers/apiController.js @@ -6,7 +6,7 @@ apiController.postCommand = (req, res, next) => { console.log(currDir); // Exec is a child process in node that asynchronously creates a shell and executes the provided command // More info: https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback - exec(command, { cwd: currDir }, (err, stdout, stderr) => { + exec(`kubectl ` + command, { cwd: currDir }, (err, stdout, stderr) => { // Handle failed command execution if (err) { return next({ diff --git a/src/components/CommandLine.jsx b/src/components/CommandLine.jsx index 4230dbb..338a9ce 100644 --- a/src/components/CommandLine.jsx +++ b/src/components/CommandLine.jsx @@ -47,7 +47,7 @@ const CommandLine = (props) => { id='outlined-start-adornment' sx={{ m: 1, width: '60ch' }} InputProps={{ - startAdornment: $, + startAdornment: $kubectl, }} value={props.command} /> From 15a23ba500a29f63949084f5ad37367244bb4c25 Mon Sep 17 00:00:00 2001 From: ncordoves Date: Mon, 24 Apr 2023 12:02:23 -0400 Subject: [PATCH 02/25] Installs typescript to dependencies, adds typescript config files --- package-lock.json | 34 +++++++++++++++++++++++++++------- package.json | 3 ++- tsconfig.json | 21 +++++++++++++++++++++ tsconfig.node.json | 9 +++++++++ 4 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 tsconfig.json create mode 100644 tsconfig.node.json diff --git a/package-lock.json b/package-lock.json index d0bfaa1..41ef796 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,11 +26,12 @@ "react-router-dom": "^6.10.0" }, "devDependencies": { - "@types/react": "^18.0.28", + "@types/react": "^18.0.38", "@types/react-dom": "^18.0.11", "@vitejs/plugin-react": "^3.1.0", "electron": "^24.0.0", "https": "^1.0.0", + "typescript": "^5.0.4", "vite": "^4.2.0" } }, @@ -1307,9 +1308,9 @@ "integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==" }, "node_modules/@types/react": { - "version": "18.0.34", - "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.34.tgz", - "integrity": "sha512-NO1UO8941541CJl1BeOXi8a9dNKFK09Gnru5ZJqkm4Q3/WoQJtHvmwt0VX0SB9YCEwe7TfSSxDuaNmx6H2BAIQ==", + "version": "18.0.38", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.38.tgz", + "integrity": "sha512-ExsidLLSzYj4cvaQjGnQCk4HFfVT9+EZ9XZsQ8Hsrcn8QNgXtpZ3m9vSIC2MWtx7jHictK6wYhQgGh6ic58oOw==", "dependencies": { "@types/prop-types": "*", "@types/scheduler": "*", @@ -4744,6 +4745,19 @@ "node": ">= 0.6" } }, + "node_modules/typescript": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", + "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=12.20" + } + }, "node_modules/undefsafe": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", @@ -5834,9 +5848,9 @@ "integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==" }, "@types/react": { - "version": "18.0.34", - "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.34.tgz", - "integrity": "sha512-NO1UO8941541CJl1BeOXi8a9dNKFK09Gnru5ZJqkm4Q3/WoQJtHvmwt0VX0SB9YCEwe7TfSSxDuaNmx6H2BAIQ==", + "version": "18.0.38", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.38.tgz", + "integrity": "sha512-ExsidLLSzYj4cvaQjGnQCk4HFfVT9+EZ9XZsQ8Hsrcn8QNgXtpZ3m9vSIC2MWtx7jHictK6wYhQgGh6ic58oOw==", "requires": { "@types/prop-types": "*", "@types/scheduler": "*", @@ -8419,6 +8433,12 @@ "mime-types": "~2.1.24" } }, + "typescript": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", + "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", + "dev": true + }, "undefsafe": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", diff --git a/package.json b/package.json index b4e9563..0ceeba2 100644 --- a/package.json +++ b/package.json @@ -30,11 +30,12 @@ "react-router-dom": "^6.10.0" }, "devDependencies": { - "@types/react": "^18.0.28", + "@types/react": "^18.0.38", "@types/react-dom": "^18.0.11", "@vitejs/plugin-react": "^3.1.0", "electron": "^24.0.0", "https": "^1.0.0", + "typescript": "^5.0.4", "vite": "^4.2.0" } } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..829a8fe --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "target": "ESNext", + "useDefineForClassFields": true, + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "allowJs": false, + "skipLibCheck": true, + "esModuleInterop": false, + "allowSyntheticDefaultImports": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "module": "ESNext", + "moduleResolution": "Node", + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx" + }, + "include": ["src"], + "references": [{ "path": "./tsconfig.node.json" }] + } \ No newline at end of file diff --git a/tsconfig.node.json b/tsconfig.node.json new file mode 100644 index 0000000..eedc67d --- /dev/null +++ b/tsconfig.node.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "composite": true, + "module": "ESNext", + "moduleResolution": "Node", + "allowSyntheticDefaultImports": true + }, + "include": ["vite.config.ts"] + } \ No newline at end of file From 80159c6ad3dfacf3528fc0e8d118ad7537304476 Mon Sep 17 00:00:00 2001 From: ncordoves Date: Mon, 24 Apr 2023 14:28:00 -0400 Subject: [PATCH 03/25] Installs dependencies, adds watch script --- .vscode/settings.json | 3 + package-lock.json | 154 ++++++++++++++++++++++++++++++++++++++++-- package.json | 5 +- 3 files changed, 155 insertions(+), 7 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..55712c1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "typescript.tsdk": "node_modules/typescript/lib" +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 41ef796..7522387 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,6 +26,8 @@ "react-router-dom": "^6.10.0" }, "devDependencies": { + "@types/express": "^4.17.17", + "@types/node": "^18.16.0", "@types/react": "^18.0.38", "@types/react-dom": "^18.0.11", "@vitejs/plugin-react": "^3.1.0", @@ -1255,6 +1257,16 @@ "node": ">=10" } }, + "node_modules/@types/body-parser": { + "version": "1.19.2", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.2.tgz", + "integrity": "sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g==", + "dev": true, + "dependencies": { + "@types/connect": "*", + "@types/node": "*" + } + }, "node_modules/@types/cacheable-request": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.3.tgz", @@ -1272,6 +1284,38 @@ "resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.2.tgz", "integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==" }, + "node_modules/@types/connect": { + "version": "3.4.35", + "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.35.tgz", + "integrity": "sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/express": { + "version": "4.17.17", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.17.tgz", + "integrity": "sha512-Q4FmmuLGBG58btUnfS1c1r/NQdlp3DMfGDGig8WhfpA2YRUtEkxAjkZb0yvplJGYdF1fsQ81iMDcH24sSCNC/Q==", + "dev": true, + "dependencies": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "^4.17.33", + "@types/qs": "*", + "@types/serve-static": "*" + } + }, + "node_modules/@types/express-serve-static-core": { + "version": "4.17.33", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.33.tgz", + "integrity": "sha512-TPBqmR/HRYI3eC2E5hmiivIzv+bidAfXofM+sbonAGvyDhySGw9/PQZFt2BLOrjUUR++4eJVpx6KnLQK1Fk9tA==", + "dev": true, + "dependencies": { + "@types/node": "*", + "@types/qs": "*", + "@types/range-parser": "*" + } + }, "node_modules/@types/http-cache-semantics": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz", @@ -1292,10 +1336,16 @@ "@types/node": "*" } }, + "node_modules/@types/mime": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@types/mime/-/mime-3.0.1.tgz", + "integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==", + "dev": true + }, "node_modules/@types/node": { - "version": "18.15.11", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.11.tgz", - "integrity": "sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==" + "version": "18.16.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.0.tgz", + "integrity": "sha512-BsAaKhB+7X+H4GnSjGhJG9Qi8Tw+inU9nJDwmD5CgOmBLEI6ArdhikpLX7DjbjDRDTbqZzU2LSQNZg8WGPiSZQ==" }, "node_modules/@types/parse-json": { "version": "4.0.0", @@ -1307,6 +1357,18 @@ "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz", "integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==" }, + "node_modules/@types/qs": { + "version": "6.9.7", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz", + "integrity": "sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==", + "dev": true + }, + "node_modules/@types/range-parser": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.4.tgz", + "integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==", + "dev": true + }, "node_modules/@types/react": { "version": "18.0.38", "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.38.tgz", @@ -1367,6 +1429,16 @@ "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.3.tgz", "integrity": "sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ==" }, + "node_modules/@types/serve-static": { + "version": "1.15.1", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.15.1.tgz", + "integrity": "sha512-NUo5XNiAdULrJENtJXZZ3fHtfMolzZwczzBbnAeBbqBwG+LaG6YaJtuwzwGSQZ2wsCrxjEhNNjAkKigy3n8teQ==", + "dev": true, + "dependencies": { + "@types/mime": "*", + "@types/node": "*" + } + }, "node_modules/@types/tough-cookie": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.2.tgz", @@ -5795,6 +5867,16 @@ "defer-to-connect": "^2.0.0" } }, + "@types/body-parser": { + "version": "1.19.2", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.2.tgz", + "integrity": "sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g==", + "dev": true, + "requires": { + "@types/connect": "*", + "@types/node": "*" + } + }, "@types/cacheable-request": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.3.tgz", @@ -5812,6 +5894,38 @@ "resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.2.tgz", "integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==" }, + "@types/connect": { + "version": "3.4.35", + "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.35.tgz", + "integrity": "sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, + "@types/express": { + "version": "4.17.17", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.17.tgz", + "integrity": "sha512-Q4FmmuLGBG58btUnfS1c1r/NQdlp3DMfGDGig8WhfpA2YRUtEkxAjkZb0yvplJGYdF1fsQ81iMDcH24sSCNC/Q==", + "dev": true, + "requires": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "^4.17.33", + "@types/qs": "*", + "@types/serve-static": "*" + } + }, + "@types/express-serve-static-core": { + "version": "4.17.33", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.33.tgz", + "integrity": "sha512-TPBqmR/HRYI3eC2E5hmiivIzv+bidAfXofM+sbonAGvyDhySGw9/PQZFt2BLOrjUUR++4eJVpx6KnLQK1Fk9tA==", + "dev": true, + "requires": { + "@types/node": "*", + "@types/qs": "*", + "@types/range-parser": "*" + } + }, "@types/http-cache-semantics": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz", @@ -5832,10 +5946,16 @@ "@types/node": "*" } }, + "@types/mime": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@types/mime/-/mime-3.0.1.tgz", + "integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==", + "dev": true + }, "@types/node": { - "version": "18.15.11", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.11.tgz", - "integrity": "sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==" + "version": "18.16.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.0.tgz", + "integrity": "sha512-BsAaKhB+7X+H4GnSjGhJG9Qi8Tw+inU9nJDwmD5CgOmBLEI6ArdhikpLX7DjbjDRDTbqZzU2LSQNZg8WGPiSZQ==" }, "@types/parse-json": { "version": "4.0.0", @@ -5847,6 +5967,18 @@ "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz", "integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==" }, + "@types/qs": { + "version": "6.9.7", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz", + "integrity": "sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==", + "dev": true + }, + "@types/range-parser": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.4.tgz", + "integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==", + "dev": true + }, "@types/react": { "version": "18.0.38", "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.38.tgz", @@ -5907,6 +6039,16 @@ "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.3.tgz", "integrity": "sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ==" }, + "@types/serve-static": { + "version": "1.15.1", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.15.1.tgz", + "integrity": "sha512-NUo5XNiAdULrJENtJXZZ3fHtfMolzZwczzBbnAeBbqBwG+LaG6YaJtuwzwGSQZ2wsCrxjEhNNjAkKigy3n8teQ==", + "dev": true, + "requires": { + "@types/mime": "*", + "@types/node": "*" + } + }, "@types/tough-cookie": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.2.tgz", diff --git a/package.json b/package.json index 0ceeba2..07b017b 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "start": "electron .", "dev": "concurrently \"nodemon server/server.js\" \"vite dev\" --host 0.0.0.0", "build": "vite build", - "preview": "vite preview" + "preview": "vite preview", + "watch": "npx tsc -w" }, "dependencies": { "@emotion/react": "^11.10.6", @@ -30,6 +31,8 @@ "react-router-dom": "^6.10.0" }, "devDependencies": { + "@types/express": "^4.17.17", + "@types/node": "^18.16.0", "@types/react": "^18.0.38", "@types/react-dom": "^18.0.11", "@vitejs/plugin-react": "^3.1.0", From 497fdbe1887e779b393b1af902d09dfa6a6454db Mon Sep 17 00:00:00 2001 From: ncordoves Date: Mon, 24 Apr 2023 14:28:14 -0400 Subject: [PATCH 04/25] Converts server to typescript --- server/server.ts | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 server/server.ts diff --git a/server/server.ts b/server/server.ts new file mode 100644 index 0000000..5a70038 --- /dev/null +++ b/server/server.ts @@ -0,0 +1,64 @@ +import * as express from 'express'; +import apiRouter from './routes/apiRouter.ts'; +import userRouter from './routes/userRouter.ts'; +import clusterRouter from './routes/clusterRouter.ts' +import mongoose from 'mongoose'; +import path from 'path'; + +const app = express(); + +// changing port here for grafana +const PORT: number = 6666; + +// Connect to mongo database +mongoose.connect( + 'mongodb+srv://osp5:9dm8OGGfECIJmZdQ@cluster.zboxzus.mongodb.net/test' +); + +// Upon successful connection, send update to console +mongoose.connection.once('open', (): void => { + console.log('WE IN DIS DB'); +}); + +// Add body parser +app.use(express.json()); + +// Handle routes to /api +app.use('/api', apiRouter); + +// Handle routes to /user +app.use('/user', userRouter); + +app.use(express.static(path.join(__dirname, '../index'))); + +// Yining addition: Handle routes to /clusterinfo +app.use('/clusterinfo', clusterRouter); + +// Handle invalid endpoint +app.use((req: express.Request, res: express.Response) => { + res.status(404).send('Not Found'); +}); + +//creates type for error handler +type ErrHndl = { + log: string, + status: number, + message: { + err: string, + } +}; + +// Handle errors +app.use((err: string, req: express.Request, res: express.Response) => { + const defaultErr: ErrHndl = { + log: 'Express error handler caught unknown middleware error', + status: 500, + message: { err: 'An error occurred' }, + }; + const errorObj: ErrHndl = Object.assign({}, defaultErr, err); + return res.status(errorObj.status).json(errorObj.message); +}); + +app.listen(PORT, (): void=> console.log(`Listening on port ${PORT}`)); + +module.exports = app; From b9c31eac78fa1baf96edb7fd0316b1553791ee49 Mon Sep 17 00:00:00 2001 From: ncordoves Date: Mon, 24 Apr 2023 14:28:41 -0400 Subject: [PATCH 05/25] Converts router to typescript --- server/routes/apiRouter.js | 11 ----------- server/routes/apiRouter.ts | 10 ++++++++++ server/routes/clusterRouter.js | 16 ---------------- server/routes/clusterRouter.ts | 15 +++++++++++++++ server/routes/userRouter.js | 15 --------------- server/routes/userRouter.ts | 15 +++++++++++++++ 6 files changed, 40 insertions(+), 42 deletions(-) delete mode 100644 server/routes/apiRouter.js create mode 100644 server/routes/apiRouter.ts delete mode 100644 server/routes/clusterRouter.js create mode 100644 server/routes/clusterRouter.ts delete mode 100644 server/routes/userRouter.js create mode 100644 server/routes/userRouter.ts diff --git a/server/routes/apiRouter.js b/server/routes/apiRouter.js deleted file mode 100644 index 2604dcc..0000000 --- a/server/routes/apiRouter.js +++ /dev/null @@ -1,11 +0,0 @@ -const express = require('express'); - -const apiController = require('../controllers/apiController.js'); - -const router = express.Router(); - -router.post('/', apiController.postCommand, (req, res) => { - return res.status(200).json(res.locals.cliResponse); -}); - -module.exports = router; diff --git a/server/routes/apiRouter.ts b/server/routes/apiRouter.ts new file mode 100644 index 0000000..d8b4006 --- /dev/null +++ b/server/routes/apiRouter.ts @@ -0,0 +1,10 @@ +import * as express from 'express'; +import apiController from '../controllers/apiController.js'; + +const apiRouter = express.Router(); + +apiRouter.post('/', apiController.postCommand, (req: express.Request, res: express.Response) => { + return res.status(200).json(res.locals.cliResponse); +}); + +export default apiRouter; diff --git a/server/routes/clusterRouter.js b/server/routes/clusterRouter.js deleted file mode 100644 index 4065f7f..0000000 --- a/server/routes/clusterRouter.js +++ /dev/null @@ -1,16 +0,0 @@ -const express = require('express'); -const router = express.Router(); -const clusterController = require('../controllers/clusterController'); - - -// router.get('/', clusterController.getClusterInfo, (req, res) => { -// return res.status(200); -// }) - -router.get( '/', clusterController.getPods, (req, res) => { - return res.status(200); -}) - - -module.exports = router; - diff --git a/server/routes/clusterRouter.ts b/server/routes/clusterRouter.ts new file mode 100644 index 0000000..d24bade --- /dev/null +++ b/server/routes/clusterRouter.ts @@ -0,0 +1,15 @@ +import * as express from 'express'; +import clusterController from '../controllers/clusterController'; + +const clusterRouter = express.Router(); + +// router.get('/', clusterController.getClusterInfo, (req, res) => { +// return res.status(200); +// }) + +clusterRouter.get( '/', clusterController.getPods, (req: express.Request, res: express.Response) => { + return res.status(200); +}) + +export default clusterRouter; + diff --git a/server/routes/userRouter.js b/server/routes/userRouter.js deleted file mode 100644 index 6ecd805..0000000 --- a/server/routes/userRouter.js +++ /dev/null @@ -1,15 +0,0 @@ -const express = require('express'); -const router = express.Router(); -const userController = require('../controllers/userController'); - -// Handle POST request to create new user -router.post('/createuser', userController.createUser, (req, res) => { - res.status(200).json('User Created'); -}); - -// Handle POST request to verify user on login -router.post('/login', userController.verifyUser, (req, res) => { - res.status(200).json('Login Successful'); -}); - -module.exports = router; diff --git a/server/routes/userRouter.ts b/server/routes/userRouter.ts new file mode 100644 index 0000000..b3639da --- /dev/null +++ b/server/routes/userRouter.ts @@ -0,0 +1,15 @@ +import * as express from 'express' +import userController from '../controller/userController.js' + +const userRouter = express.Router(); +// Handle POST request to create new user +userRouter.post('/createuser', userController.createUser, (req: express.Request, res: express.Response) => { + res.status(200).json('User Created'); +}); + +// Handle POST request to verify user on login +userRouter.post('/login', userController.verifyUser, (req: express.Request, res: express.Response) => { + res.status(200).json('Login Successful'); +}); + +export default userRouter; From 14c63182cc0e79f4b70e57915b387ce5eaa91956 Mon Sep 17 00:00:00 2001 From: ncordoves Date: Mon, 24 Apr 2023 15:31:33 -0400 Subject: [PATCH 06/25] Converts controllers to typescript --- .../{apiController.js => apiController.ts} | 12 ++-- ...sterController.js => clusterController.ts} | 21 +++--- .../{userController.js => userController.ts} | 29 +++++---- server/models/UserModel.js | 4 +- server/routes/userRouter.ts | 2 +- server/server.js | 65 ------------------- tsconfig.json | 5 +- 7 files changed, 41 insertions(+), 97 deletions(-) rename server/controllers/{apiController.js => apiController.ts} (72%) rename server/controllers/{clusterController.js => clusterController.ts} (50%) rename server/controllers/{userController.js => userController.ts} (60%) delete mode 100644 server/server.js diff --git a/server/controllers/apiController.js b/server/controllers/apiController.ts similarity index 72% rename from server/controllers/apiController.js rename to server/controllers/apiController.ts index 4302b7e..46269f0 100644 --- a/server/controllers/apiController.js +++ b/server/controllers/apiController.ts @@ -1,12 +1,14 @@ -const apiController = {}; -const { exec } = require('child_process'); +import { exec } from 'child_process'; +import * as express from 'express'; -apiController.postCommand = (req, res, next) => { +const apiController: { [key: string]: any } = {}; + +apiController.postCommand = (req: express.Request, res: express.Response, next: express.NextFunction) => { const { command, currDir } = req.body; console.log(currDir); // Exec is a child process in node that asynchronously creates a shell and executes the provided command // More info: https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback - exec(` ${command}`, { cwd: currDir }, (err, stdout, stderr) => { + exec(` ${command}`, { cwd: currDir }, (err: Error | null, stdout: string, stderr: string) => { // Handle failed command execution if (err) { return next({ @@ -30,4 +32,4 @@ apiController.postCommand = (req, res, next) => { }); }; -module.exports = apiController; +export default apiController; diff --git a/server/controllers/clusterController.js b/server/controllers/clusterController.ts similarity index 50% rename from server/controllers/clusterController.js rename to server/controllers/clusterController.ts index da787fc..609e508 100644 --- a/server/controllers/clusterController.js +++ b/server/controllers/clusterController.ts @@ -1,6 +1,7 @@ -const clusterController = {}; -const k8s = require('@kubernetes/client-node'); -const { HttpStatusCode } = require('axios'); +import k8s from '@kubernetes/client-node'; +import * as express from 'express'; + +const clusterController: { [key: string]: any} = {} const kc = new k8s.KubeConfig(); kc.loadFromDefault(); @@ -8,7 +9,7 @@ kc.loadFromDefault(); const k8sApi = kc.makeApiClient(k8s.CoreV1Api); // GET ALL PODS -clusterController.getPods = async (req, res, next) => { +clusterController.getPods = async (req: express.Request, res: express.Response, next: express.NextFunction): Promise => { await k8sApi.listNamespacedPod('default').then((res) => { console.log('we getting dem pods'); console.log(res.body); @@ -18,7 +19,7 @@ clusterController.getPods = async (req, res, next) => { }; // GET NAMESPACES -clusterController.getNameSpaces = async (req, res, next) => { +clusterController.getNameSpaces = async (req: express.Request, res: express.Response, next: express.NextFunction): Promise => { await k8sApi.listNamespace('default').then((res) => { console.log(res.body); return next(); @@ -26,11 +27,11 @@ clusterController.getNameSpaces = async (req, res, next) => { }; // GET CLUSTER INFO -clusterController.getClusterInfo = async (req, res, next) => { +clusterController.getClusterInfo = async (req: express.Request, res: express.Response, next: express.NextFunction): Promise => { try { - const pods = await getPods(); - const namespaces = await getNameSpaces(); - const clusterInfo = { pods, namespaces }; + const pods = await clusterController.getPods(); + const namespaces = await clusterController.getNameSpaces(); + const clusterInfo = { pods: [], namespaces: [] }; console.log('cluser info', clusterInfo); return next(); } catch (err) { @@ -42,4 +43,4 @@ clusterController.getClusterInfo = async (req, res, next) => { } }; -module.exports = clusterController; +export default clusterController; diff --git a/server/controllers/userController.js b/server/controllers/userController.ts similarity index 60% rename from server/controllers/userController.js rename to server/controllers/userController.ts index d92848e..9592162 100644 --- a/server/controllers/userController.js +++ b/server/controllers/userController.ts @@ -1,15 +1,18 @@ -const Users = require('../models/userModel'); -var qs = require('querystring'); -const bcrypt = require('bcryptjs'); +import Users from '../models/UserModel'; +import bcrypt from 'bcryptjs'; +import * as express from 'express'; -const userController = {}; +const userController: Record = {} -// Create user in the database -userController.createUser = async (req, res, next) => { - const { username, email, password } = req.body; +type CreateUserRequestBody = Record<'username' | 'email' | 'password', string> + +type VerifyUserRequestBody = Record<'username' | 'password', string> +// Create user in the database +userController.createUser = async (req: express.Request, res: express.Response, next: express.NextFunction): Promise => { + const { username, email, password } = req.body as CreateUserRequestBody; try { - const newUser = await Users.create({ username, email, password }); + await Users.create({ username, email, password }); // If the user is created, return next return next(); } catch (err) { @@ -17,14 +20,14 @@ userController.createUser = async (req, res, next) => { next({ log: 'Express error handler caught createUser middleware error', status: 400, - message: { err: err.message }, + message: { err: 'An error occured CREATE' }, }); } }; // Verify user on login attempt -userController.verifyUser = async (req, res, next) => { - const { username, password } = req.body; +userController.verifyUser = async (req: express.Request, res: express.Response, next: express.NextFunction): Promise => { + const { username, password } = req.body as VerifyUserRequestBody; // Find if the user exists in the database const user = await Users.findOne({ username }); // If user does not exist, return error @@ -35,7 +38,7 @@ userController.verifyUser = async (req, res, next) => { message: { err: 'An error occurred EMAIL' }, }); } else { - bcrypt.compare(password, user.password, (err, result) => { + bcrypt.compare(password, user.password, (err: Error, result: boolean) => { // If there is an error in hashing the password, return error if (err) { return next({ @@ -62,4 +65,4 @@ userController.verifyUser = async (req, res, next) => { } }; -module.exports = userController; +export default userController; diff --git a/server/models/UserModel.js b/server/models/UserModel.js index 3f82fb7..71d6540 100644 --- a/server/models/UserModel.js +++ b/server/models/UserModel.js @@ -45,4 +45,6 @@ userSchema.pre('save', function (next) { const Users = mongoose.model('users', userSchema); -module.exports = Users; // <-- export your model +// module.exports = Users; // <-- export your model + +export default Users; \ No newline at end of file diff --git a/server/routes/userRouter.ts b/server/routes/userRouter.ts index b3639da..34a8813 100644 --- a/server/routes/userRouter.ts +++ b/server/routes/userRouter.ts @@ -1,5 +1,5 @@ import * as express from 'express' -import userController from '../controller/userController.js' +import userController from '../controllers/userController' const userRouter = express.Router(); // Handle POST request to create new user diff --git a/server/server.js b/server/server.js deleted file mode 100644 index e2b8dc5..0000000 --- a/server/server.js +++ /dev/null @@ -1,65 +0,0 @@ -const express = require('express'); -const app = express(); -const path = require('path'); -const apiRouter = require('./routes/apiRouter.js'); -const userRouter = require('./routes/userRouter.js'); -const clusterRouter = require('./routes/clusterRouter.js') -const mongoose = require('mongoose'); - -// changing port here for grafana -const PORT = 6666; - -// Connect to mongo database -mongoose.connect( - 'mongodb+srv://osp5:9dm8OGGfECIJmZdQ@cluster.zboxzus.mongodb.net/test' -); - -// Upon successful connection, send update to console -mongoose.connection.once('open', () => { - console.log('WE IN DIS DB'); -}); - -// Add body parser -app.use(express.json()); - -// Handle routes to /api -app.use('/api', apiRouter); - -// Handle routes to /user -app.use('/user', userRouter); - -app.use(express.static(path.join(__dirname, '../index'))); - -// Yining addition: Handle routes to /clusterinfo -app.use('/clusterinfo', clusterRouter); - -// app.get('/', (req, res) => { -// res.status(200).sendFile(path.join(__dirname, '/index.html')); -// res.send('weinhere'); -// }); - -//ADD DASHBOARD ROUTE TO SERVE DASHBOARD UPON LOGIN?? -// app.get('/dashboard', (req, res) => { -// res.status(200).sendFile(path.join(__dirname, '/Dashboard.jsx')); -// // res.send('weinhere') -// }); - -// Handle invalid endpoint -app.use((req, res) => { - res.status(404).send('Not Found'); -}); - -// Handle errors -app.use((err, req, res, next) => { - const defaultErr = { - log: 'Express error handler caught unknown middleware error', - status: 500, - message: { err: 'An error occurred' }, - }; - const errorObj = Object.assign({}, defaultErr, err); - return res.status(errorObj.status).json(errorObj.message); -}); - -app.listen(PORT, () => console.log(`Listening on port ${PORT}`)); - -module.exports = app; diff --git a/tsconfig.json b/tsconfig.json index 829a8fe..5d13b99 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,8 +14,9 @@ "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, - "jsx": "react-jsx" + "jsx": "react-jsx", + "allowImportingTsExtensions": true }, - "include": ["src"], + "include": ["src", "server"], "references": [{ "path": "./tsconfig.node.json" }] } \ No newline at end of file From ce8eeb18e973dee326887af2f8d72fb9694e67bd Mon Sep 17 00:00:00 2001 From: ncordoves Date: Mon, 24 Apr 2023 16:57:57 -0400 Subject: [PATCH 07/25] Converts model to typescript --- package-lock.json | 13 +++++++++++++ package.json | 3 ++- server/cli.js | 0 server/controllers/userController.ts | 2 +- server/models/{UserModel.js => UserModel.ts} | 20 ++++++++------------ 5 files changed, 24 insertions(+), 14 deletions(-) delete mode 100644 server/cli.js rename server/models/{UserModel.js => UserModel.ts} (62%) diff --git a/package-lock.json b/package-lock.json index 7522387..9d68be4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,6 +26,7 @@ "react-router-dom": "^6.10.0" }, "devDependencies": { + "@types/bcryptjs": "^2.4.2", "@types/express": "^4.17.17", "@types/node": "^18.16.0", "@types/react": "^18.0.38", @@ -1257,6 +1258,12 @@ "node": ">=10" } }, + "node_modules/@types/bcryptjs": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/@types/bcryptjs/-/bcryptjs-2.4.2.tgz", + "integrity": "sha512-LiMQ6EOPob/4yUL66SZzu6Yh77cbzJFYll+ZfaPiPPFswtIlA/Fs1MzdKYA7JApHU49zQTbJGX3PDmCpIdDBRQ==", + "dev": true + }, "node_modules/@types/body-parser": { "version": "1.19.2", "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.2.tgz", @@ -5867,6 +5874,12 @@ "defer-to-connect": "^2.0.0" } }, + "@types/bcryptjs": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/@types/bcryptjs/-/bcryptjs-2.4.2.tgz", + "integrity": "sha512-LiMQ6EOPob/4yUL66SZzu6Yh77cbzJFYll+ZfaPiPPFswtIlA/Fs1MzdKYA7JApHU49zQTbJGX3PDmCpIdDBRQ==", + "dev": true + }, "@types/body-parser": { "version": "1.19.2", "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.2.tgz", diff --git a/package.json b/package.json index 07b017b..5a67c1d 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "dev": "concurrently \"nodemon server/server.js\" \"vite dev\" --host 0.0.0.0", "build": "vite build", "preview": "vite preview", - "watch": "npx tsc -w" + "watch": "npx tsc -w" }, "dependencies": { "@emotion/react": "^11.10.6", @@ -31,6 +31,7 @@ "react-router-dom": "^6.10.0" }, "devDependencies": { + "@types/bcryptjs": "^2.4.2", "@types/express": "^4.17.17", "@types/node": "^18.16.0", "@types/react": "^18.0.38", diff --git a/server/cli.js b/server/cli.js deleted file mode 100644 index e69de29..0000000 diff --git a/server/controllers/userController.ts b/server/controllers/userController.ts index 9592162..c209afc 100644 --- a/server/controllers/userController.ts +++ b/server/controllers/userController.ts @@ -65,4 +65,4 @@ userController.verifyUser = async (req: express.Request, res: express.Response, } }; -export default userController; +export default userController; \ No newline at end of file diff --git a/server/models/UserModel.js b/server/models/UserModel.ts similarity index 62% rename from server/models/UserModel.js rename to server/models/UserModel.ts index 71d6540..7d8ff72 100644 --- a/server/models/UserModel.js +++ b/server/models/UserModel.ts @@ -1,9 +1,10 @@ // // v-- REPLACE THE EMPTY STRING WITH YOUR LOCAL/MLAB/ELEPHANTSQL URI -const mongoose = require('mongoose'); -const myURI = 'mongodb+srv://osp5:9dm8OGGfECIJmZdQ@cluster.zboxzus.mongodb.net/test'; -const bcrypt = require('bcryptjs') -// UNCOMMENT THE LINE BELOW IF USING MONGO -const URI = process.env.MONGO_URI || myURI; +import mongoose from 'mongoose'; +import bcrypt from 'bcryptjs'; + +const myURI: string = 'mongodb+srv://osp5:9dm8OGGfECIJmZdQ@cluster.zboxzus.mongodb.net/test'; + +const URI: string = process.env.MONGO_URI || myURI; // mongoose.connect(URI, { // useNewUrlParser: true, @@ -11,9 +12,6 @@ const URI = process.env.MONGO_URI || myURI; // dbName: 'Task' // }); -// UNCOMMENT THE LINE BELOW IF USING POSTGRESQL -// const URI = process.env.PG_URI || myURI; - const Schema = mongoose.Schema; @@ -29,11 +27,11 @@ userSchema.pre('save', function (next) { if (!user.isModified('password')) { return next(); } - bcrypt.genSalt(10, function (err, salt) { + bcrypt.genSalt(10, function (err: Error, salt: string) { if (err) { return next(err); } - bcrypt.hash(user.password, salt, function (err, hash) { + bcrypt.hash(user.password, salt, function (err, hash: string) { if (err) { return next(err); } @@ -45,6 +43,4 @@ userSchema.pre('save', function (next) { const Users = mongoose.model('users', userSchema); -// module.exports = Users; // <-- export your model - export default Users; \ No newline at end of file From 5e553ca828cdfd6c344d27ae419aa52d2c60ec1f Mon Sep 17 00:00:00 2001 From: ncordoves Date: Thu, 27 Apr 2023 10:25:58 -0400 Subject: [PATCH 08/25] Adds tsconfig gile --- tsconfig.node.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tsconfig.node.json b/tsconfig.node.json index eedc67d..af73888 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -5,5 +5,5 @@ "moduleResolution": "Node", "allowSyntheticDefaultImports": true }, - "include": ["vite.config.ts"] - } \ No newline at end of file + "include": ["vite.config.js"] +} \ No newline at end of file From 06a28d41014143af79d4b2e13aff4f65550fb1e8 Mon Sep 17 00:00:00 2001 From: ncordoves Date: Thu, 27 Apr 2023 14:03:43 -0400 Subject: [PATCH 09/25] Fixes server bugs --- package.json | 11 ++++--- server/controllers/clusterController.ts | 1 + server/controllers/userController.ts | 2 ++ server/routes/apiRouter.ts | 2 +- server/server.ts | 9 ++++-- tsconfig.json | 41 ++++++++++++------------- vite.config.ts | 21 +++++++++++++ 7 files changed, 57 insertions(+), 30 deletions(-) create mode 100644 vite.config.ts diff --git a/package.json b/package.json index 45640be..79bcbf6 100644 --- a/package.json +++ b/package.json @@ -3,16 +3,16 @@ "productName": "Kaptn", "private": true, "version": "0.0.0", - "type": "commonjs", "main": "main.js", "scripts": { "start": "electron .", - "dev": "concurrently \"nodemon server/server.js\" \"vite dev\" --host 0.0.0.0", + "dev-f": "nodemon server/server.ts", + "dev-b": "vite dev --host 0.0.0.0", "watch": "npx tsc -w", - "build": "vite build && npm run pack && node server/server.js", + "build": "vite build && npm run pack", "postinstall": "electron-builder install-app-deps", "pack": "electron-builder -mwl", - "preview": "vite preview", + "preview": "vite preview", "vite": "vite" }, "dependencies": { @@ -31,7 +31,8 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-pro-sidebar": "^1.0.0", - "react-router-dom": "^6.10.0" + "react-router-dom": "^6.10.0", + "ts-node": "^10.9.1" }, "devDependencies": { "@types/bcryptjs": "^2.4.2", diff --git a/server/controllers/clusterController.ts b/server/controllers/clusterController.ts index 609e508..dcc5903 100644 --- a/server/controllers/clusterController.ts +++ b/server/controllers/clusterController.ts @@ -4,6 +4,7 @@ import * as express from 'express'; const clusterController: { [key: string]: any} = {} const kc = new k8s.KubeConfig(); + kc.loadFromDefault(); const k8sApi = kc.makeApiClient(k8s.CoreV1Api); diff --git a/server/controllers/userController.ts b/server/controllers/userController.ts index c209afc..8233f9b 100644 --- a/server/controllers/userController.ts +++ b/server/controllers/userController.ts @@ -27,7 +27,9 @@ userController.createUser = async (req: express.Request, res: express.Response, // Verify user on login attempt userController.verifyUser = async (req: express.Request, res: express.Response, next: express.NextFunction): Promise => { + console.log('in verify user') const { username, password } = req.body as VerifyUserRequestBody; + console.log(req.body); // Find if the user exists in the database const user = await Users.findOne({ username }); // If user does not exist, return error diff --git a/server/routes/apiRouter.ts b/server/routes/apiRouter.ts index d8b4006..da00a5d 100644 --- a/server/routes/apiRouter.ts +++ b/server/routes/apiRouter.ts @@ -1,5 +1,5 @@ import * as express from 'express'; -import apiController from '../controllers/apiController.js'; +import apiController from '../controllers/apiController.ts'; const apiRouter = express.Router(); diff --git a/server/server.ts b/server/server.ts index 5a70038..9a5f55a 100644 --- a/server/server.ts +++ b/server/server.ts @@ -1,4 +1,5 @@ -import * as express from 'express'; +// import * as express from 'express'; +import express, { Express, Request, Response } from 'express'; import apiRouter from './routes/apiRouter.ts'; import userRouter from './routes/userRouter.ts'; import clusterRouter from './routes/clusterRouter.ts' @@ -32,7 +33,7 @@ app.use('/user', userRouter); app.use(express.static(path.join(__dirname, '../index'))); // Yining addition: Handle routes to /clusterinfo -app.use('/clusterinfo', clusterRouter); +// app.use('/clusterinfo', clusterRouter); // Handle invalid endpoint app.use((req: express.Request, res: express.Response) => { @@ -59,6 +60,8 @@ app.use((err: string, req: express.Request, res: express.Response) => { return res.status(errorObj.status).json(errorObj.message); }); -app.listen(PORT, (): void=> console.log(`Listening on port ${PORT}`)); +console.log(PORT) + +app.listen(PORT, () => console.log(`Listening on port ${PORT}`)); module.exports = app; diff --git a/tsconfig.json b/tsconfig.json index 5d13b99..63e6578 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,22 +1,21 @@ { - "compilerOptions": { - "target": "ESNext", - "useDefineForClassFields": true, - "lib": ["DOM", "DOM.Iterable", "ESNext"], - "allowJs": false, - "skipLibCheck": true, - "esModuleInterop": false, - "allowSyntheticDefaultImports": true, - "strict": true, - "forceConsistentCasingInFileNames": true, - "module": "ESNext", - "moduleResolution": "Node", - "resolveJsonModule": true, - "isolatedModules": true, - "noEmit": true, - "jsx": "react-jsx", - "allowImportingTsExtensions": true - }, - "include": ["src", "server"], - "references": [{ "path": "./tsconfig.node.json" }] - } \ No newline at end of file + "compilerOptions": { + "target": "ES6", + "module": "commonjs", + "jsx": "react", + "esModuleInterop": true, + "lib": ["dom", "es2021"], + "allowJs": true, + "sourceMap": true, + "outDir": "./dist", + "strict": true, + "moduleResolution": "node", + "removeComments": true, + "noEmit": true, + "allowSyntheticDefaultImports": true, + "noImplicitAny": false, + "strictNullChecks": false, + "allowImportingTsExtensions": true, + }, + "include": ["src/**/*", "server/**/*", "global.d.ts"] +} \ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts new file mode 100644 index 0000000..ed59e0e --- /dev/null +++ b/vite.config.ts @@ -0,0 +1,21 @@ +import { defineConfig } from 'vite'; +import react from '@vitejs/plugin-react'; + +export default defineConfig({ + plugins: [react()], + base: './', + server: { + port: 4444, + host: true, + proxy: { + '/api': { + target: 'http://localhost:6666', + changeOrigin: true, + }, + '/user': { + target: 'http://localhost:6666', + changeOrigin: true, + }, + }, + }, +}); From 6f1a1569494fbe42acb8dc72a4b9887a3c55f486 Mon Sep 17 00:00:00 2001 From: ncordoves Date: Thu, 27 Apr 2023 14:06:13 -0400 Subject: [PATCH 10/25] Fixes concurrently bug --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 79bcbf6..5d5b8e4 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,7 @@ "main": "main.js", "scripts": { "start": "electron .", - "dev-f": "nodemon server/server.ts", - "dev-b": "vite dev --host 0.0.0.0", + "dev": "concurrently \"nodemon server/server.ts\" \"vite dev\" --host 0.0.0.0", "watch": "npx tsc -w", "build": "vite build && npm run pack", "postinstall": "electron-builder install-app-deps", From 476761e7d4754a246d394b7d98a58473d7c2e1fb Mon Sep 17 00:00:00 2001 From: ncordoves Date: Thu, 27 Apr 2023 14:23:01 -0400 Subject: [PATCH 11/25] Adds dist and build to gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f69ccb3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +build/ +dist/ \ No newline at end of file From 3f21059f02ca1ce8afb1fc8ce781b37dc6d568a5 Mon Sep 17 00:00:00 2001 From: Olivia Hodel Date: Thu, 27 Apr 2023 18:49:45 -0400 Subject: [PATCH 12/25] Converts dashboard component and theme into typescript --- src/.DS_Store | Bin 0 -> 6148 bytes src/{App.jsx => App.tsx} | 0 src/Pages/.DS_Store | Bin 0 -> 6148 bytes src/Pages/{Dashboard.jsx => Dashboard.tsx} | 78 +++++++++++++-------- src/Pages/Login.jsx | 2 +- src/Pages/Signup.jsx | 2 +- src/components/Sidebar.jsx | 12 ++-- src/components/Topbar.jsx | 5 +- src/constants 2.js | 7 ++ src/{theme.js => theme.ts} | 0 tsconfig.json | 6 +- 11 files changed, 65 insertions(+), 47 deletions(-) create mode 100644 src/.DS_Store rename src/{App.jsx => App.tsx} (100%) create mode 100644 src/Pages/.DS_Store rename src/Pages/{Dashboard.jsx => Dashboard.tsx} (85%) create mode 100644 src/constants 2.js rename src/{theme.js => theme.ts} (100%) diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..51707bc4eafe75f6d920425142e71d07f06b518f GIT binary patch literal 6148 zcmeH~J&pn~427RrkdU^a+%gRZ;06(5PrwD(1w@0yN@)8WooB}l12r0r2wyw<3^dk@$ KG>E`U3ETkUhZBha literal 0 HcmV?d00001 diff --git a/src/App.jsx b/src/App.tsx similarity index 100% rename from src/App.jsx rename to src/App.tsx diff --git a/src/Pages/.DS_Store b/src/Pages/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..40fa5ec3c16d31fbd459e3d04201910961d311cc GIT binary patch literal 6148 zcmeH~I|@QU3`G+^AlO)1PU8aH!64cTZon@#f`!=6(!Kd0__P+08%XXSEGM}gZ->kNdcAm6FKev^j^B7a&tnP+kN^pg011%5 z4-v3?8#Wq;GLirZkie6Gy&nqPw5GODe{~@E2ml=*?S{3_63}7^XiaUQ$iOsOq0y>7 zhFIR)p(X2TY732a(HuTB|5(''); + const [type, setType] = useState(''); + const [name, setName] = useState(''); + const [currDir, setCurrDir] = useState('NONE SELECTED'); + const [userInput, setUserInput] = useState(''); + const [command, setCommand] = useState(''); + const [tool, setTool] = useState(''); + const [response, setResponse] = useState< + Array<{ command: string; response: { [key: string]: string } }> + >([]); + const [flags, setFlags] = useState>([]); - // Set flag list state + // Set flag list state on change const handleFlags = (event) => { const { target: { value }, @@ -43,6 +48,14 @@ function Dashboard() { ); }; + // Set name state on change + const handleNameChange = (event) => { + const { + target: { value }, + } = event; + setName(value); + } + // Set current directory state const handleUploadDirectory = (event) => { let path = event.target.files[0].path.split(''); @@ -61,6 +74,10 @@ function Dashboard() { if (verb !== '') newCommand += ' ' + verb; if (type !== '') newCommand += ' ' + type; if (name !== '') newCommand += ' ' + name; + if (flags.length) + flags.forEach((flag) => { + newCommand += ' ' + flag; + }); if (userInput !== '') newCommand += ' ' + userInput; setCommand(newCommand); }); @@ -79,7 +96,6 @@ function Dashboard() { return cliResponse; } catch (e) { console.log(e); - setError(true); } }; @@ -92,7 +108,10 @@ function Dashboard() { console.log('command ', command); const getCliResponse = async () => { - const cliResponse = await postCommand(command, currDir); + const cliResponse: { [key: string]: string } = await postCommand( + command, + currDir + ); // Filter for errors if (cliResponse.err) alert('Invalid command. Please try again'); // Update response state with the returned CLI response @@ -139,12 +158,15 @@ function Dashboard() { { label: 'services' }, ]; + // Flag list options + const flagList = ['-o wide', '--force']; + return ( <>