From 6fcb8addf191ede02fb7a100d37922bbf95a3662 Mon Sep 17 00:00:00 2001 From: coderharsh77 <89582365+coderharsh77@users.noreply.github.com> Date: Wed, 30 Oct 2024 15:45:47 +0530 Subject: [PATCH 01/44] fix: remove wrong dimensions from browser dimensions --- src/components/organisms/BrowserWindow.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/organisms/BrowserWindow.tsx b/src/components/organisms/BrowserWindow.tsx index 3cfc2b3d..84011ae3 100644 --- a/src/components/organisms/BrowserWindow.tsx +++ b/src/components/organisms/BrowserWindow.tsx @@ -66,7 +66,6 @@ export const BrowserWindow = () => { const { socket } = useSocketStore(); const { notify } = useGlobalInfoStore(); - //const { width, height } = useBrowserDimensionsStore(); const { getText, getList, paginationMode, paginationType, limitMode } = useActionContext(); const { addTextStep, addListStep } = useBrowserSteps(); @@ -405,4 +404,4 @@ const modalStyle = { height: 'fit-content', display: 'block', padding: '20px', -}; \ No newline at end of file +}; From ea6ef56e228d923514d71951f628937fd9144ac1 Mon Sep 17 00:00:00 2001 From: coderharsh77 <89582365+coderharsh77@users.noreply.github.com> Date: Wed, 30 Oct 2024 15:46:29 +0530 Subject: [PATCH 02/44] chore: remove useBrowserDimension import --- src/components/organisms/BrowserWindow.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/organisms/BrowserWindow.tsx b/src/components/organisms/BrowserWindow.tsx index 84011ae3..cbc46731 100644 --- a/src/components/organisms/BrowserWindow.tsx +++ b/src/components/organisms/BrowserWindow.tsx @@ -2,7 +2,6 @@ import React, { useCallback, useEffect, useState } from 'react'; import { useSocketStore } from '../../context/socket'; import { Button } from '@mui/material'; import Canvas from "../atoms/canvas"; -import { useBrowserDimensionsStore } from "../../context/browserDimensions"; import { Highlighter } from "../atoms/Highlighter"; import { GenericModal } from '../atoms/GenericModal'; import { useActionContext } from '../../context/browserActions'; From 7689a0b1592fc19d1c41bb483f8418d9e7e35f39 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 30 Oct 2024 21:06:39 +0530 Subject: [PATCH 03/44] fix: swagger spec in production --- server/src/swagger/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/swagger/config.ts b/server/src/swagger/config.ts index 040db66c..c9c12210 100644 --- a/server/src/swagger/config.ts +++ b/server/src/swagger/config.ts @@ -25,7 +25,7 @@ const options = { }, ], }, - apis: [path.join(__dirname, '../api/*.ts')], + apis: process.env.NODE_ENV === 'production' ? [path.join(__dirname, '../api/*.js')] : [path.join(__dirname, '../api/*.ts')] }; const swaggerSpec = swaggerJSDoc(options); From 4d2f0ed5bfa3f40a713d25bf5664fb03767a25a6 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 30 Oct 2024 21:12:51 +0530 Subject: [PATCH 04/44] feat: fork worker only in dev mode --- server/src/server.ts | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/server/src/server.ts b/server/src/server.ts index 5c7fc898..65d0d67f 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -62,24 +62,24 @@ readdirSync(path.join(__dirname, 'api')).forEach((r) => { } }); -// Check if we're running in production or development const isProduction = process.env.NODE_ENV === 'production'; const workerPath = path.resolve(__dirname, isProduction ? './worker.js' : '/worker.ts'); -// Fork the worker process -const workerProcess = fork(workerPath, [], { - execArgv: isProduction ? ['--inspect=8081'] : ['--inspect=5859'], -}); - -workerProcess.on('message', (message) => { - console.log(`Message from worker: ${message}`); -}); -workerProcess.on('error', (error) => { - console.error(`Error in worker: ${error}`); -}); -workerProcess.on('exit', (code) => { - console.log(`Worker exited with code: ${code}`); -}); +let workerProcess; +if (!isProduction) { + workerProcess = fork(workerPath, [], { + execArgv: ['--inspect=5859'], + }); + workerProcess.on('message', (message) => { + console.log(`Message from worker: ${message}`); + }); + workerProcess.on('error', (error) => { + console.error(`Error in worker: ${error}`); + }); + workerProcess.on('exit', (code) => { + console.log(`Worker exited with code: ${code}`); + }); +} app.get('/', function (req, res) { capture( @@ -98,6 +98,6 @@ server.listen(SERVER_PORT, async () => { process.on('SIGINT', () => { console.log('Main app shutting down...'); - workerProcess.kill(); + //workerProcess.kill(); process.exit(); }); From 25e3eadc7347356f93da8f8c8a3207fae2fb497a Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 30 Oct 2024 21:13:31 +0530 Subject: [PATCH 05/44] fix: missing algorithm key --- server/src/utils/auth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/utils/auth.ts b/server/src/utils/auth.ts index e73a4237..f8313df7 100644 --- a/server/src/utils/auth.ts +++ b/server/src/utils/auth.ts @@ -36,7 +36,7 @@ export const encrypt = (text: string): string => { export const decrypt = (encryptedText: string): string => { const [iv, encrypted] = encryptedText.split(':'); - const algorithm = getEnvVariable('ALGORITHM'); + const algorithm = "aes-256-cbc"; const key = Buffer.from(getEnvVariable('ENCRYPTION_KEY'), 'hex'); const decipher = crypto.createDecipheriv(algorithm, key, Buffer.from(iv, 'hex')); let decrypted = decipher.update(encrypted, 'hex', 'utf8'); From fa416469d6fd1aa67858cf326a97dfc7f7f6b8b7 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 30 Oct 2024 21:38:00 +0530 Subject: [PATCH 06/44] feat: postgres healtcheck --- docker-compose.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index f36e8900..5b850297 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,6 +25,11 @@ services: - "5432:5432" volumes: - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 10s + timeout: 5s + retries: 5 minio: image: minio/minio From 17b65032971ab4c4089b625594eb24d93a62aa4a Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 30 Oct 2024 22:04:40 +0530 Subject: [PATCH 07/44] feat: get host from url.hostname --- server/src/storage/db.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/src/storage/db.ts b/server/src/storage/db.ts index 6a23ef42..2f0fcde4 100644 --- a/server/src/storage/db.ts +++ b/server/src/storage/db.ts @@ -3,10 +3,15 @@ import dotenv from 'dotenv'; import setupAssociations from '../models/associations'; dotenv.config(); -const sequelize = new Sequelize( - `postgresql://${process.env.DB_USER}:${process.env.DB_PASSWORD}@${process.env.DB_HOST}:${process.env.DB_PORT}/${process.env.DB_NAME}`, + +const databaseUrl = `postgresql://${process.env.DB_USER}:${process.env.DB_PASSWORD}@${process.env.DB_HOST}:${process.env.DB_PORT}/${process.env.DB_NAME}`; + +// Extract the hostname using the URL constructor +const host = new URL(databaseUrl).hostname; + +const sequelize = new Sequelize(databaseUrl, { - host: process.env.DB_HOST, + host, dialect: 'postgres', logging: false, } From 80238fbf5e7c1ce7e7c6837aa822340f4cd650e0 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 30 Oct 2024 22:05:16 +0530 Subject: [PATCH 08/44] feat: fork worker in dev mode --- server/src/server.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/server/src/server.ts b/server/src/server.ts index 65d0d67f..2dd9a2da 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -63,20 +63,20 @@ readdirSync(path.join(__dirname, 'api')).forEach((r) => { }); const isProduction = process.env.NODE_ENV === 'production'; -const workerPath = path.resolve(__dirname, isProduction ? './worker.js' : '/worker.ts'); +const workerPath = path.resolve(__dirname, isProduction ? './worker.js' : './worker.ts'); -let workerProcess; +let workerProcess: any; if (!isProduction) { workerProcess = fork(workerPath, [], { execArgv: ['--inspect=5859'], }); - workerProcess.on('message', (message) => { + workerProcess.on('message', (message: any) => { console.log(`Message from worker: ${message}`); }); - workerProcess.on('error', (error) => { + workerProcess.on('error', (error: any) => { console.error(`Error in worker: ${error}`); }); - workerProcess.on('exit', (code) => { + workerProcess.on('exit', (code: any) => { console.log(`Worker exited with code: ${code}`); }); } @@ -91,13 +91,21 @@ app.get('/', function (req, res) { }); server.listen(SERVER_PORT, async () => { - await connectDB(); - await syncDB(); - logger.log('info', `Server listening on port ${SERVER_PORT}`); + try { + await connectDB(); + await syncDB(); + logger.log('info', `Server listening on port ${SERVER_PORT}`); + } catch (error: any) { + logger.log('error', `Failed to connect to the database: ${error.message}`); + process.exit(1); // Exit the process if DB connection fails + } }); + process.on('SIGINT', () => { console.log('Main app shutting down...'); - //workerProcess.kill(); + if (!isProduction) { + workerProcess.kill(); + } process.exit(); }); From 1ecc16d6f8f366caebd3a875c5eed06169be5c5d Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 30 Oct 2024 22:05:53 +0530 Subject: [PATCH 09/44] fix: format --- server/src/server.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/server.ts b/server/src/server.ts index 2dd9a2da..4ad71ac4 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -84,8 +84,8 @@ if (!isProduction) { app.get('/', function (req, res) { capture( 'maxun-oss-server-run', { - event: 'server_started', - } + event: 'server_started', + } ); return res.send('Maxun server started 🚀'); }); From 7c963ed10d46adfd91091aa288fc27b247d01dd9 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 31 Oct 2024 14:15:47 +0530 Subject: [PATCH 10/44] feat: error handling --- server/src/routes/auth.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index d4104f19..6766a356 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -14,6 +14,8 @@ interface AuthenticatedRequest extends Request { } router.post('/register', async (req, res) => { + console.log('Received request at /auth/register'); + console.log('Received body:', req.body); try { const { email, password } = req.body @@ -25,7 +27,21 @@ router.post('/register', async (req, res) => { const hashedPassword = await hashPassword(password) - const user = await User.create({ email, password: hashedPassword }); + let user: any; + + try { + user = await User.create({ email, password: hashedPassword }); + } catch ( + error: any + ) { + console.log(`Could not create user - ${error}`) + return res.status(500).send(`Could not create user - ${error.message}`) + } + + if (!process.env.JWT_SECRET) { + console.log('JWT_SECRET is not defined in the environment'); + return res.status(500).send('Internal Server Error'); + } const token = jwt.sign({ id: user.id }, process.env.JWT_SECRET as string, { expiresIn: '12h' }); user.password = undefined as unknown as string @@ -40,8 +56,10 @@ router.post('/register', async (req, res) => { registeredAt: new Date().toISOString() } ) + console.log(`User registered - ${user.email}`) res.json(user) } catch (error: any) { + console.log(`Could not register user - ${error}`) res.status(500).send(`Could not register user - ${error.message}`) } }) From 69ff7125aa84727eb3cbaac9fcffc60c7372c34d Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 31 Oct 2024 14:16:27 +0530 Subject: [PATCH 11/44] feat: add cors header --- server/src/server.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/server/src/server.ts b/server/src/server.ts index 4ad71ac4..e6fee5f2 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -39,8 +39,8 @@ export const io = new Server(server); */ export const browserPool = new BrowserPool(); -app.use(bodyParser.json({ limit: '10mb' })) -app.use(bodyParser.urlencoded({ extended: true, limit: '10mb', parameterLimit: 9000 })); +// app.use(bodyParser.json({ limit: '10mb' })) +// app.use(bodyParser.urlencoded({ extended: true, limit: '10mb', parameterLimit: 9000 })); // parse cookies - "cookie" is true in csrfProtection app.use(cookieParser()) @@ -90,7 +90,18 @@ app.get('/', function (req, res) { return res.send('Maxun server started 🚀'); }); -server.listen(SERVER_PORT, async () => { +// Add CORS headers +app.use((req, res, next) => { + res.header('Access-Control-Allow-Origin', '*'); + res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); + res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization'); + if (req.method === 'OPTIONS') { + return res.sendStatus(200); + } + next(); +}); + +server.listen(SERVER_PORT, '0.0.0.0', async () => { try { await connectDB(); await syncDB(); @@ -101,7 +112,6 @@ server.listen(SERVER_PORT, async () => { } }); - process.on('SIGINT', () => { console.log('Main app shutting down...'); if (!isProduction) { From 4ebe37290887d38ee415f971613ea335f2cd699b Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 31 Oct 2024 14:46:33 +0530 Subject: [PATCH 12/44] chore: handle timeouts --- nginx.conf | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/nginx.conf b/nginx.conf index e9d636f8..1ea52146 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,17 +1,45 @@ server { listen 80; - + location / { root /usr/share/nginx/html; try_files $uri $uri/ /index.html; } location /api { - proxy_pass http://127.0.0.1:8080; + proxy_pass http://localhost:8080; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; + + # Add timeout configurations + proxy_connect_timeout 60s; + proxy_send_timeout 60s; + proxy_read_timeout 60s; + + # Add error handling + proxy_intercept_errors on; + error_page 502 503 504 /50x.html; + } + + location ~ ^/(record|workflow|storage|auth|integration|proxy|api-docs) { + proxy_pass http://localhost:8080; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'keep-alive'; # Ensure connections remain open + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + + # Timeout configurations + proxy_connect_timeout 60s; + proxy_send_timeout 60s; + proxy_read_timeout 60s; + + # Error handling for these routes + proxy_intercept_errors on; + error_page 502 503 504 /50x.html; } } \ No newline at end of file From db840bd1b4851760882ca913d2331961cc9bf8ce Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 31 Oct 2024 15:25:23 +0530 Subject: [PATCH 13/44] chore: app healthcheck --- docker-compose.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 5b850297..e64ab0d3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,12 +8,15 @@ services: target: production env_file: .env ports: - - "5173:80" - - "8080:8080" + - "5173:80" # Only expose Nginx depends_on: - - db - - minio - - redis + db: + condition: service_healthy + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8080/"] + interval: 10s + timeout: 5s + retries: 5 db: image: postgres:13 From 2adc7843d9ba509dbb6de722192e59c7eef89468 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 31 Oct 2024 15:25:49 +0530 Subject: [PATCH 14/44] chore: bind host 0.0.0.0 --- docker-entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 7e36eed4..e40af108 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/sh # Start backend server -cd /app && npm run start:server & +cd /app && npm run start:server -- --host 0.0.0.0 & # Start nginx -nginx -g 'daemon off;' \ No newline at end of file +nginx -g 'daemon off;' From e8208772f1f809ecf285fb06182bcc6c7efde960 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Fri, 1 Nov 2024 07:40:06 +0530 Subject: [PATCH 15/44] fix: handle vite env variables --- Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Dockerfile b/Dockerfile index d7abca37..a03c84df 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,6 +29,10 @@ RUN npm run build:server FROM base AS frontend-build WORKDIR /app +# Define the environment variable to make it available at build time +ARG VITE_BACKEND_URL +ENV VITE_BACKEND_URL=$VITE_BACKEND_URL + # Copy frontend code and configs COPY src ./src COPY index.html ./index.html From bb38786027b576536e86d4981b44c3fece1ac4a0 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Fri, 1 Nov 2024 07:41:38 +0530 Subject: [PATCH 16/44] chore: healthcheck --- docker-compose.yml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index e64ab0d3..f133eb3b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,14 +6,16 @@ services: context: . dockerfile: Dockerfile target: production + args: + VITE_BACKEND_URL: ${VITE_BACKEND_URL} env_file: .env ports: - - "5173:80" # Only expose Nginx + - "5173:80" # Frontend exposed on port 5173 depends_on: db: condition: service_healthy healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:8080/"] + test: ["CMD", "curl", "-f", "http://app:80/"] # Changed to port 80 interval: 10s timeout: 5s retries: 5 @@ -55,6 +57,15 @@ services: volumes: - redis_data:/data + nginx: + image: nginx:latest + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf # Your Nginx config + ports: + - "80:80" # Host port 80 mapped to Nginx port 80 + depends_on: + - app + volumes: postgres_data: minio_data: From ba9e04657624715dee5fb9fcf3152f8c922cdca6 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Fri, 1 Nov 2024 08:25:14 +0530 Subject: [PATCH 17/44] refactor: use apiUrl --- src/api/auth.ts | 3 ++- src/api/integration.ts | 3 ++- src/api/proxy.ts | 9 +++++---- src/api/recording.ts | 15 ++++++++------- src/api/storage.ts | 25 +++++++++++++------------ src/api/workflow.ts | 11 ++++++----- 6 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/api/auth.ts b/src/api/auth.ts index 34ebcab8..32a11f69 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -1,8 +1,9 @@ import { default as axios } from "axios"; +import { apiUrl } from "../apiConfig" export const getUserById = async (userId: string) => { try { - const response = await axios.get(`http://localhost:8080/auth/user/${userId}`); + const response = await axios.get(`${apiUrl}/auth/user/${userId}`); if (response.status === 200) { return response.data; } else { diff --git a/src/api/integration.ts b/src/api/integration.ts index 2804508b..d484abbb 100644 --- a/src/api/integration.ts +++ b/src/api/integration.ts @@ -1,8 +1,9 @@ import { default as axios } from "axios"; +import { apiUrl } from "../apiConfig"; export const handleUploadCredentials = async (fileName: string, credentials: any, spreadsheetId: string, range: string): Promise => { try { - const response = await axios.post('http://localhost:8080/integration/upload-credentials', { fileName, credentials: JSON.parse(credentials), spreadsheetId, range }); + const response = await axios.post(`${apiUrl}/integration/upload-credentials`, { fileName, credentials: JSON.parse(credentials), spreadsheetId, range }); if (response.status === 200) { return response.data; } else { diff --git a/src/api/proxy.ts b/src/api/proxy.ts index 4ca79742..e08dcfae 100644 --- a/src/api/proxy.ts +++ b/src/api/proxy.ts @@ -1,8 +1,9 @@ import { default as axios } from "axios"; +import { apiUrl } from "../apiConfig"; export const sendProxyConfig = async (proxyConfig: { server_url: string, username?: string, password?: string }): Promise => { try { - const response = await axios.post(`http://localhost:8080/proxy/config`, proxyConfig); + const response = await axios.post(`${apiUrl}/proxy/config`, proxyConfig); if (response.status === 200) { return response.data; } else { @@ -16,7 +17,7 @@ export const sendProxyConfig = async (proxyConfig: { server_url: string, usernam export const getProxyConfig = async (): Promise<{ proxy_url: string, auth: boolean }> => { try { - const response = await axios.get(`http://localhost:8080/proxy/config`); + const response = await axios.get(`${apiUrl}/proxy/config`); if (response.status === 200) { return response.data; } else { @@ -30,7 +31,7 @@ export const getProxyConfig = async (): Promise<{ proxy_url: string, auth: boole export const testProxyConfig = async (): Promise<{ success: boolean }> => { try { - const response = await axios.get(`http://localhost:8080/proxy/test`); + const response = await axios.get(`${apiUrl}/proxy/test`); if (response.status === 200) { return response.data; } else { @@ -44,7 +45,7 @@ export const testProxyConfig = async (): Promise<{ success: boolean }> => { export const deleteProxyConfig = async (): Promise => { try { - const response = await axios.delete(`http://localhost:8080/proxy/config`); + const response = await axios.delete(`${apiUrl}/proxy/config`); if (response.status === 200) { return response.data; } else { diff --git a/src/api/recording.ts b/src/api/recording.ts index ef51a476..6b816001 100644 --- a/src/api/recording.ts +++ b/src/api/recording.ts @@ -1,8 +1,9 @@ import { default as axios, AxiosResponse } from "axios"; +import { apiUrl } from "../apiConfig"; export const startRecording = async() : Promise => { try { - const response = await axios.get('http://localhost:8080/record/start') + const response = await axios.get(`${apiUrl}/record/start`) if (response.status === 200) { return response.data; } else { @@ -14,7 +15,7 @@ export const startRecording = async() : Promise => { }; export const stopRecording = async (id: string): Promise => { - await axios.get(`http://localhost:8080/record/stop/${id}`) + await axios.get(`${apiUrl}/record/stop/${id}`) .then((response : AxiosResponse) => { }) .catch((error: any) => { @@ -23,7 +24,7 @@ export const stopRecording = async (id: string): Promise => { export const getActiveBrowserId = async(): Promise => { try { - const response = await axios.get('http://localhost:8080/record/active'); + const response = await axios.get(`${apiUrl}/record/active`); if (response.status === 200) { return response.data; } else { @@ -36,7 +37,7 @@ export const getActiveBrowserId = async(): Promise => { export const interpretCurrentRecording = async(): Promise => { try { - const response = await axios.get('http://localhost:8080/record/interpret'); + const response = await axios.get(`${apiUrl}/record/interpret`); if (response.status === 200) { return true; } else { @@ -50,7 +51,7 @@ export const interpretCurrentRecording = async(): Promise => { export const stopCurrentInterpretation = async(): Promise => { try { - const response = await axios.get('http://localhost:8080/record/interpret/stop'); + const response = await axios.get(`${apiUrl}/record/interpret/stop`); if (response.status === 200) { return; } else { @@ -63,7 +64,7 @@ export const stopCurrentInterpretation = async(): Promise => { export const getCurrentUrl = async (): Promise => { try { - const response = await axios.get('http://localhost:8080/record/active/url'); + const response = await axios.get(`${apiUrl}/record/active/url`); if (response.status === 200) { return response.data; } else { @@ -77,7 +78,7 @@ export const getCurrentUrl = async (): Promise => { export const getCurrentTabs = async (): Promise => { try { - const response = await axios.get('http://localhost:8080/record/active/tabs'); + const response = await axios.get(`${apiUrl}/record/active/tabs`); if (response.status === 200) { return response.data; } else { diff --git a/src/api/storage.ts b/src/api/storage.ts index da017027..9b4b06b2 100644 --- a/src/api/storage.ts +++ b/src/api/storage.ts @@ -3,10 +3,11 @@ import { WorkflowFile } from "maxun-core"; import { RunSettings } from "../components/molecules/RunSettings"; import { ScheduleSettings } from "../components/molecules/ScheduleSettings"; import { CreateRunResponse, ScheduleRunResponse } from "../pages/MainPage"; +import { apiUrl } from "../apiConfig"; export const getStoredRecordings = async (): Promise => { try { - const response = await axios.get('http://localhost:8080/storage/recordings'); + const response = await axios.get(`${apiUrl}/storage/recordings`); if (response.status === 200) { return response.data; } else { @@ -20,7 +21,7 @@ export const getStoredRecordings = async (): Promise => { export const getStoredRuns = async (): Promise => { try { - const response = await axios.get('http://localhost:8080/storage/runs'); + const response = await axios.get(`${apiUrl}/storage/runs`); if (response.status === 200) { return response.data; } else { @@ -34,7 +35,7 @@ export const getStoredRuns = async (): Promise => { export const getStoredRecording = async (id: string) => { try { - const response = await axios.get(`http://localhost:8080/storage/recordings/${id}`); + const response = await axios.get(`${apiUrl}/storage/recordings/${id}`); if (response.status === 200) { return response.data; } else { @@ -48,7 +49,7 @@ export const getStoredRecording = async (id: string) => { export const deleteRecordingFromStorage = async (id: string): Promise => { try { - const response = await axios.delete(`http://localhost:8080/storage/recordings/${id}`); + const response = await axios.delete(`${apiUrl}/storage/recordings/${id}`); if (response.status === 200) { return response.data; } else { @@ -62,7 +63,7 @@ export const deleteRecordingFromStorage = async (id: string): Promise = export const deleteRunFromStorage = async (id: string): Promise => { try { - const response = await axios.delete(`http://localhost:8080/storage/runs/${id}`); + const response = await axios.delete(`${apiUrl}/storage/runs/${id}`); if (response.status === 200) { return response.data; } else { @@ -76,7 +77,7 @@ export const deleteRunFromStorage = async (id: string): Promise => { export const editRecordingFromStorage = async (browserId: string, id: string): Promise => { try { - const response = await axios.put(`http://localhost:8080/workflow/${browserId}/${id}`); + const response = await axios.put(`${apiUrl}/workflow/${browserId}/${id}`); if (response.status === 200) { return response.data; } else { @@ -91,7 +92,7 @@ export const editRecordingFromStorage = async (browserId: string, id: string): P export const createRunForStoredRecording = async (id: string, settings: RunSettings): Promise => { try { const response = await axios.put( - `http://localhost:8080/storage/runs/${id}`, + `${apiUrl}/storage/runs/${id}`, { ...settings }); if (response.status === 200) { return response.data; @@ -106,7 +107,7 @@ export const createRunForStoredRecording = async (id: string, settings: RunSetti export const interpretStoredRecording = async (id: string): Promise => { try { - const response = await axios.post(`http://localhost:8080/storage/runs/run/${id}`); + const response = await axios.post(`${apiUrl}/storage/runs/run/${id}`); if (response.status === 200) { return response.data; } else { @@ -120,7 +121,7 @@ export const interpretStoredRecording = async (id: string): Promise => export const notifyAboutAbort = async (id: string): Promise => { try { - const response = await axios.post(`http://localhost:8080/storage/runs/abort/${id}`); + const response = await axios.post(`${apiUrl}/storage/runs/abort/${id}`); if (response.status === 200) { return response.data; } else { @@ -135,7 +136,7 @@ export const notifyAboutAbort = async (id: string): Promise => { export const scheduleStoredRecording = async (id: string, settings: ScheduleSettings): Promise => { try { const response = await axios.put( - `http://localhost:8080/storage/schedule/${id}`, + `${apiUrl}/storage/schedule/${id}`, { ...settings }); if (response.status === 200) { return response.data; @@ -150,7 +151,7 @@ export const scheduleStoredRecording = async (id: string, settings: ScheduleSett export const getSchedule = async (id: string) => { try { - const response = await axios.get(`http://localhost:8080/storage/schedule/${id}`); + const response = await axios.get(`${apiUrl}/storage/schedule/${id}`); if (response.status === 200) { return response.data.schedule; } else { @@ -164,7 +165,7 @@ export const getSchedule = async (id: string) => { export const deleteSchedule = async (id: string): Promise => { try { - const response = await axios.delete(`http://localhost:8080/storage/schedule/${id}`); + const response = await axios.delete(`${apiUrl}/storage/schedule/${id}`); if (response.status === 200) { return response.data; } else { diff --git a/src/api/workflow.ts b/src/api/workflow.ts index a32b6cbc..03b677b1 100644 --- a/src/api/workflow.ts +++ b/src/api/workflow.ts @@ -1,10 +1,11 @@ import { WhereWhatPair, WorkflowFile } from "maxun-core"; import { emptyWorkflow } from "../shared/constants"; import { default as axios, AxiosResponse } from "axios"; +import { apiUrl } from "../apiConfig"; export const getActiveWorkflow = async(id: string) : Promise => { try { - const response = await axios.get(`http://localhost:8080/workflow/${id}`) + const response = await axios.get(`${apiUrl}/workflow/${id}`) if (response.status === 200) { return response.data; } else { @@ -18,7 +19,7 @@ export const getActiveWorkflow = async(id: string) : Promise => { export const getParamsOfActiveWorkflow = async(id: string) : Promise => { try { - const response = await axios.get(`http://localhost:8080/workflow/params/${id}`) + const response = await axios.get(`${apiUrl}/workflow/params/${id}`) if (response.status === 200) { return response.data; } else { @@ -32,7 +33,7 @@ export const getParamsOfActiveWorkflow = async(id: string) : Promise => { try { - const response = await axios.delete(`http://localhost:8080/workflow/pair/${index}`); + const response = await axios.delete(`${apiUrl}/workflow/pair/${index}`); if (response.status === 200) { return response.data; } else { @@ -46,7 +47,7 @@ export const deletePair = async(index: number): Promise => { export const AddPair = async(index: number, pair: WhereWhatPair): Promise => { try { - const response = await axios.post(`http://localhost:8080/workflow/pair/${index}`, { + const response = await axios.post(`${apiUrl}/workflow/pair/${index}`, { pair, }, {headers: {'Content-Type': 'application/json'}}); if (response.status === 200) { @@ -62,7 +63,7 @@ export const AddPair = async(index: number, pair: WhereWhatPair): Promise => { try { - const response = await axios.put(`http://localhost:8080/workflow/pair/${index}`, { + const response = await axios.put(`${apiUrl}/workflow/pair/${index}`, { pair, }, {headers: {'Content-Type': 'application/json'}}); if (response.status === 200) { From a0eb6d427ec4d155b3334fff76bdf9f1daacdf31 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Fri, 1 Nov 2024 08:25:33 +0530 Subject: [PATCH 18/44] refactor: use apiUrl --- src/components/molecules/IntegrationSettings.tsx | 11 ++++++----- src/components/molecules/NavBar.tsx | 3 ++- src/components/organisms/ApiKey.tsx | 7 ++++--- src/components/organisms/MainMenu.tsx | 3 ++- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/components/molecules/IntegrationSettings.tsx b/src/components/molecules/IntegrationSettings.tsx index f47ac5da..1150dd72 100644 --- a/src/components/molecules/IntegrationSettings.tsx +++ b/src/components/molecules/IntegrationSettings.tsx @@ -6,6 +6,7 @@ import TextField from "@mui/material/TextField"; import axios from 'axios'; import { useGlobalInfoStore } from '../../context/globalInfo'; import { getStoredRecording } from '../../api/storage'; +import { apiUrl } from '../../apiConfig.js'; interface IntegrationProps { isOpen: boolean; handleStart: (data: IntegrationSettings) => void; @@ -32,12 +33,12 @@ export const IntegrationSettingsModal = ({ isOpen, handleStart, handleClose }: I const [recording, setRecording] = useState(null); const authenticateWithGoogle = () => { - window.location.href = `http://localhost:8080/auth/google?robotId=${recordingId}`; + window.location.href = `${apiUrl}/auth/google?robotId=${recordingId}`; }; const handleOAuthCallback = async () => { try { - const response = await axios.get(`http://localhost:8080/auth/google/callback`); + const response = await axios.get(`${apiUrl}/auth/google/callback`); const { google_sheet_email, files } = response.data; } catch (error) { setError('Error authenticating with Google'); @@ -46,7 +47,7 @@ export const IntegrationSettingsModal = ({ isOpen, handleStart, handleClose }: I const fetchSpreadsheetFiles = async () => { try { - const response = await axios.get(`http://localhost:8080/auth/gsheets/files?robotId=${recordingId}`, { + const response = await axios.get(`${apiUrl}/auth/gsheets/files?robotId=${recordingId}`, { withCredentials: true, }); setSpreadsheets(response.data); @@ -66,7 +67,7 @@ export const IntegrationSettingsModal = ({ isOpen, handleStart, handleClose }: I const updateGoogleSheetId = async () => { try { const response = await axios.post( - `http://localhost:8080/auth/gsheets/update`, + `${apiUrl}/auth/gsheets/update`, { spreadsheetId: settings.spreadsheetId, spreadsheetName: settings.spreadsheetName, robotId: recordingId }, { withCredentials: true } ); @@ -79,7 +80,7 @@ export const IntegrationSettingsModal = ({ isOpen, handleStart, handleClose }: I const removeIntegration = async () => { try { await axios.post( - `http://localhost:8080/auth/gsheets/remove`, + `${apiUrl}/auth/gsheets/remove`, { robotId: recordingId }, { withCredentials: true } ); diff --git a/src/components/molecules/NavBar.tsx b/src/components/molecules/NavBar.tsx index b0a409b1..8dd678c5 100644 --- a/src/components/molecules/NavBar.tsx +++ b/src/components/molecules/NavBar.tsx @@ -9,6 +9,7 @@ import { useNavigate } from 'react-router-dom'; import { AuthContext } from '../../context/auth'; import { SaveRecording } from '../molecules/SaveRecording'; import DiscordIcon from '../atoms/DiscordIcon'; +import { apiUrl } from '../../apiConfig'; interface NavBarProps { recordingName: string; @@ -34,7 +35,7 @@ export const NavBar: React.FC = ({ recordingName, isRecording }) => const logout = async () => { dispatch({ type: 'LOGOUT' }); window.localStorage.removeItem('user'); - const { data } = await axios.get('http://localhost:8080/auth/logout'); + const { data } = await axios.get(`${apiUrl}/auth/logout`); notify('success', data.message); navigate('/login'); }; diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index 7999296b..d9f4c6fe 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -18,6 +18,7 @@ import { ContentCopy, Visibility, Delete } from '@mui/icons-material'; import styled from 'styled-components'; import axios from 'axios'; import { useGlobalInfoStore } from '../../context/globalInfo'; +import { apiUrl } from '../../apiConfig'; const Container = styled(Box)` display: flex; @@ -38,7 +39,7 @@ const ApiKeyManager = () => { useEffect(() => { const fetchApiKey = async () => { try { - const { data } = await axios.get('http://localhost:8080/auth/api-key'); + const { data } = await axios.get(`${apiUrl}/auth/api-key`); setApiKey(data.api_key); } catch (error: any) { notify('error', `Failed to fetch API Key - ${error.message}`); @@ -53,7 +54,7 @@ const ApiKeyManager = () => { const generateApiKey = async () => { setLoading(true); try { - const { data } = await axios.post('http://localhost:8080/auth/generate-api-key'); + const { data } = await axios.post(`${apiUrl}/auth/generate-api-key`); setApiKey(data.api_key); notify('success', `Generated API Key successfully`); } catch (error: any) { @@ -66,7 +67,7 @@ const ApiKeyManager = () => { const deleteApiKey = async () => { setLoading(true); try { - await axios.delete('http://localhost:8080/auth/delete-api-key'); + await axios.delete(`${apiUrl}/auth/delete-api-key`); setApiKey(null); notify('success', 'API Key deleted successfully'); } catch (error: any) { diff --git a/src/components/organisms/MainMenu.tsx b/src/components/organisms/MainMenu.tsx index 12df9350..edb6ed29 100644 --- a/src/components/organisms/MainMenu.tsx +++ b/src/components/organisms/MainMenu.tsx @@ -4,6 +4,7 @@ import Tab from '@mui/material/Tab'; import Box from '@mui/material/Box'; import { Paper, Button } from "@mui/material"; import { AutoAwesome, FormatListBulleted, VpnKey, Usb, Article, Link, CloudQueue } from "@mui/icons-material"; +import { apiUrl } from "../../apiConfig"; interface MainMenuProps { value: string; @@ -86,7 +87,7 @@ export const MainMenu = ({ value = 'recordings', handleChangeContent }: MainMenu
-