-
Notifications
You must be signed in to change notification settings - Fork 162
refactor: update API base URL and enhance request handling #1014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,6 @@ | ||||||||||||||
const API_BASE_URL = window.API_BASE_URL || 'https://api.realdevsquad.com'; | ||||||||||||||
const REPO_SYNC_API_URL = | ||||||||||||||
const API_BASE_URL = 'http://localhost:3000'; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Production API Endpoint Disabled
Tell me moreWhat is the issue?Hardcoding the API base URL to localhost removes the ability to deploy to production environments and breaks the application's functionality in non-development environments. Why this mattersThe application will fail to make API calls in production as it will attempt to reach localhost instead of the actual production API endpoint. Suggested change ∙ Feature PreviewRestore the environment-aware API base URL configuration: const API_BASE_URL = window.API_BASE_URL || 'https://api.realdevsquad.com'; Provide feedback to improve future suggestions💬 Looking for more details? Reply to this comment to chat with Korbit. |
||||||||||||||
// const API_BASE_URL = window.API_BASE_URL || 'https://api.realdevsquad.com'; | ||||||||||||||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Hardcoded localhost URL will break production deployments. The API base URL is now hardcoded to localhost, which will cause failures in production environments. The commented dynamic assignment suggests this might be temporary, but this approach creates deployment risks. Consider using environment-specific configuration instead: -const API_BASE_URL = 'http://localhost:3000';
-// const API_BASE_URL = window.API_BASE_URL || 'https://api.realdevsquad.com';
+const API_BASE_URL = window.API_BASE_URL || 'https://api.realdevsquad.com'; Alternatively, if localhost is needed for development, use a more robust environment detection mechanism. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||
const REPO_SYNC_API_URL =`` | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The backtick string literal for
Suggested change
Spotted by Diamond There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary Template Literal
Tell me moreWhat is the issue?Template literal syntax is misused with empty backticks, causing unnecessary string concatenation overhead. Why this mattersWhile minor, this creates an unnecessary string concatenation operation that impacts performance and readability. Suggested change ∙ Feature PreviewRemove the empty template literal and use a regular string: const REPO_SYNC_API_URL = 'https://staging-sync.staging-realdevsquad-com.workers.dev'; Provide feedback to improve future suggestions💬 Looking for more details? Reply to this comment to chat with Korbit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify impact of emptying REPO_SYNC_API_URL. The 🏁 Script executed: #!/bin/bash
# Search for usage of REPO_SYNC_API_URL to assess impact
rg -A 3 "REPO_SYNC_API_URL" --type js Length of output: 502 Restore a valid The constant • constants.js:3 – Suggested fix (either restore the hard-coded URL or switch to an environment variable with a fallback): - const REPO_SYNC_API_URL = ``
+ const REPO_SYNC_API_URL =
+ process.env.REPO_SYNC_API_URL ||
+ 'https://staging-sync.staging-realdevsquad-com.workers.dev'; 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||
'https://staging-sync.staging-realdevsquad-com.workers.dev'; | ||||||||||||||
Comment on lines
+3
to
4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary String Syntax
Tell me moreWhat is the issue?Empty template literal (```) followed by a string literal creates confusing and unnecessary syntax Why this mattersThis syntax could be mistaken for a template literal implementation and makes the code harder to read without providing any benefit. Suggested change ∙ Feature PreviewUse a simple string literal: const REPO_SYNC_API_URL = 'https://staging-sync.staging-realdevsquad-com.workers.dev'; Provide feedback to improve future suggestions💬 Looking for more details? Reply to this comment to chat with Korbit. |
||||||||||||||
const USER_MANAGEMENT_LINK = 'user-management-link'; | ||||||||||||||
const EXTENSION_REQUESTS_LINK = 'extension-requests-link'; | ||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
const API_BASE_URL = window.API_BASE_URL; | ||
const API_BASE_URL = 'http://localhost:3000'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded Local API URL
Tell me moreWhat is the issue?Hardcoding the API base URL to localhost removes the ability to deploy the application to different environments. Why this mattersThe application will only work in local development and will fail in production or other environments where the API is hosted at a different URL. Suggested change ∙ Feature PreviewRestore the dynamic API URL configuration and use environment variables: const API_BASE_URL = window.API_BASE_URL || 'http://localhost:3000'; Provide feedback to improve future suggestions💬 Looking for more details? Reply to this comment to chat with Korbit. |
||
// const API_BASE_URL = window.API_BASE_URL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wil change it again once done with the final testing before sending the PRs to review. thanks.
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing API URL switch context
Tell me moreWhat is the issue?The commented code lacks explanation of when to use window.API_BASE_URL vs hardcoded localhost URL. Why this mattersWithout understanding the context, other developers may accidentally commit the hardcoded localhost URL to production. Suggested change ∙ Feature Preview// Local development uses localhost, production uses window.API_BASE_URL Provide feedback to improve future suggestions💬 Looking for more details? Reply to this comment to chat with Korbit.
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Hardcoded localhost URL creates deployment risk. Same issue as in Consider using the global constant from -const API_BASE_URL = 'http://localhost:3000';
-// const API_BASE_URL = window.API_BASE_URL;
+// Use the global constant from constants.js instead of redefining
🤖 Prompt for AI Agents
|
||
const requestContainer = document.getElementById(REQUEST_CONTAINER_ID); | ||
const lastElementContainer = document.querySelector(LAST_ELEMENT_CONTAINER); | ||
const params = new URLSearchParams(window.location.search); | ||
|
@@ -142,17 +143,31 @@ onboardingExtensionTabLink.addEventListener('click', async function (event) { | |
function updateUrlWithQuery(type) { | ||
const url = new URL(window.location); | ||
url.searchParams.set('type', type.toLowerCase()); | ||
if (isDev) { | ||
url.searchParams.set('dev', 'true'); | ||
} | ||
Comment on lines
143
to
+148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent Dev Mode Persistence
Tell me moreWhat is the issue?The dev parameter is being added only when switching tabs, but not preserved when applying filters or performing other navigation actions. Why this mattersUsers will lose their development mode state when interacting with filters or other navigation features, leading to inconsistent behavior. Suggested change ∙ Feature PreviewMove the dev parameter logic to a common function that's used across all URL updates: function updateUrlParams(params) {
const url = new URL(window.location);
Object.entries(params).forEach(([key, value]) => {
url.searchParams.set(key, value);
});
if (isDev) {
url.searchParams.set('dev', 'true');
}
return url;
} Provide feedback to improve future suggestions💬 Looking for more details? Reply to this comment to chat with Korbit. |
||
|
||
window.history.pushState({ path: url.toString() }, '', url.toString()); | ||
} | ||
|
||
async function getRequests(requestType, query = {}) { | ||
let finalUrl = | ||
API_BASE_URL + | ||
(nextLink || `/requests${getQueryParamsString(requestType, query)}`); | ||
(nextLink || | ||
`/requests${getQueryParamsString( | ||
requestType, | ||
query, | ||
requestType === 'OOO' ? isDev : true, | ||
)}`); | ||
Comment on lines
+156
to
+161
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) LGTM! Proper conditional dev parameter usage. The conditional logic for passing the dev parameter to However, consider using template literals as suggested by static analysis: - let finalUrl =
- API_BASE_URL +
- (nextLink ||
- `/requests${getQueryParamsString(
- requestType,
- query,
- requestType === 'OOO' ? isDev : true,
- )}`);
+ let finalUrl = `${API_BASE_URL}${nextLink || `/requests${getQueryParamsString(
+ requestType,
+ query,
+ requestType === 'OOO' ? isDev : true,
+ )}`}`; Also applies to: 165-170 🤖 Prompt for AI Agents
|
||
|
||
if (query?.state?.[0] || query?.requestedBy) { | ||
finalUrl = | ||
API_BASE_URL + `/requests${getQueryParamsString(requestType, query)}`; | ||
API_BASE_URL + | ||
`/requests${getQueryParamsString( | ||
requestType, | ||
query, | ||
requestType === 'OOO' ? isDev : true, | ||
)}`; | ||
Comment on lines
153
to
+170
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Complex URL Construction Logic
Tell me moreWhat is the issue?URL construction logic is complex with multiple conditions and repeated patterns. Why this mattersThe URL construction is difficult to follow with nested ternaries and repeated concatenation patterns, making it hard to understand the final URL structure. Suggested change ∙ Feature Previewconst buildRequestUrl = (requestType, query) => {
const useDevParam = requestType === 'OOO' ? isDev : true;
const queryString = getQueryParamsString(requestType, query, useDevParam);
return `${API_BASE_URL}/requests${queryString}`;
};
async function getRequests(requestType, query = {}) {
const finalUrl = nextLink || buildRequestUrl(requestType, query); Provide feedback to improve future suggestions💬 Looking for more details? Reply to this comment to chat with Korbit. |
||
} | ||
const notFoundErrorMessage = | ||
requestType === ONBOARDING_EXTENSION_REQUEST_TYPE | ||
|
@@ -617,13 +632,18 @@ async function performAcceptRejectAction(isAccepted, e) { | |
let remark = document.getElementById(`remark-text-${requestId}`).value; | ||
let body = JSON.stringify({ | ||
type: currentReqType, | ||
message: remark, | ||
state: isAccepted ? 'APPROVED' : 'REJECTED', | ||
[currentReqType === 'OOO' ? 'comment' : 'message']: remark, | ||
[currentReqType === 'OOO' ? 'status' : 'state']: isAccepted | ||
? 'APPROVED' | ||
: 'REJECTED', | ||
}); | ||
if (remark === '' || remark === undefined || remark === null) { | ||
body = JSON.stringify({ | ||
type: currentReqType, | ||
state: isAccepted ? 'APPROVED' : 'REJECTED', | ||
[currentReqType === 'OOO' ? 'comment' : 'message']: remark, | ||
[currentReqType === 'OOO' ? 'status' : 'state']: isAccepted | ||
? 'APPROVED' | ||
: 'REJECTED', | ||
}); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -34,9 +34,9 @@ function createElementFromMap(domObjectMap) { | |||
return el; | ||||
} | ||||
|
||||
function getQueryParamsString(requestType, query) { | ||||
function getQueryParamsString(requestType, query, dev = true) { | ||||
const params = new URLSearchParams({ | ||||
dev: 'true', | ||||
dev, | ||||
type: requestType, | ||||
size: '12', | ||||
}); | ||||
|
@@ -71,18 +71,11 @@ function convertDateToReadableStringDate(date, format) { | |||
} | ||||
|
||||
function getFullNameOfUser(user) { | ||||
console.log('user', user); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug Log in Production Code
Tell me moreWhat is the issue?Debug console.log statement left in production code Why this mattersUnintended logging in production can expose sensitive user data and impact application performance Suggested change ∙ Feature PreviewRemove the console.log statement: function getFullNameOfUser(user) {
if (!user || typeof user !== 'object') {
return 'N/A';
}
return user.username;
} Provide feedback to improve future suggestions💬 Looking for more details? Reply to this comment to chat with Korbit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Remove debug logging statement. The - console.log('user', user); 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||
if (!user || typeof user !== 'object') { | ||||
return 'N/A'; | ||||
} | ||||
const firstName = user.first_name || 'N/A'; | ||||
const lastName = user.last_name || ''; | ||||
return ( | ||||
firstName.charAt(0).toUpperCase() + | ||||
firstName.slice(1).toLowerCase() + | ||||
' ' + | ||||
lastName.charAt(0).toUpperCase() + | ||||
lastName.slice(1).toLowerCase() | ||||
); | ||||
return user.username; | ||||
Comment on lines
73
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Misleading function name vs behavior
Tell me moreWhat is the issue?Function name is misleading as it now returns username instead of full name, and contains a debug console.log statement. Why this mattersOutdated function documentation leads to confusion about the actual behavior of the code. Suggested change ∙ Feature Preview// Rename function to Provide feedback to improve future suggestions💬 Looking for more details? Reply to this comment to chat with Korbit. |
||||
} | ||||
Comment on lines
73
to
79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function Returns Username Instead of Full Name
Tell me moreWhat is the issue?The function has been changed to return username instead of the full name, which contradicts its name and expected functionality. Why this mattersThis change creates misleading behavior where callers expect a full name but receive a username, potentially breaking UI displays and data consistency across the application. Suggested change ∙ Feature PreviewEither rename the function to function getFullNameOfUser(user) {
if (!user || typeof user !== 'object') {
return 'N/A';
}
const firstName = user.first_name || 'N/A';
const lastName = user.last_name || '';
return (
firstName.charAt(0).toUpperCase() +
firstName.slice(1).toLowerCase() +
' ' +
lastName.charAt(0).toUpperCase() +
lastName.slice(1).toLowerCase()
);
} Provide feedback to improve future suggestions💬 Looking for more details? Reply to this comment to chat with Korbit. |
||||
|
||||
function extractQueryParameters(url) { | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wil change it again once done with the final testing before sending the PRs to review. thanks.