Skip to content
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

chore: Don't break when Appsmtih API URL isn't set #37309

Merged
merged 5 commits into from
Nov 15, 2024
Merged

Conversation

sharat87
Copy link
Member

@sharat87 sharat87 commented Nov 11, 2024

We actually don't need the APPSMITH_API_BASE_URL variable to be varying in production ever at all, and the routes.ts file already does have a default for this (on EE). Let's just use that instead of throwing an impact-less error.

Ideally though, we shouldn't have this env variable at all. Less things that are configurable, less things that can break other things.

Automation

/test sanity

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11812221529
Commit: f049d46
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Wed, 13 Nov 2024 07:41:57 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced constants for API URLs to streamline endpoint configurations.
  • Bug Fixes

    • Updated API request URLs to use new constants, ensuring consistency across the application.
  • Refactor

    • Centralized route constants to improve maintainability.
    • Renamed entities in test cases for clarity while preserving functionality.
  • Chores

    • Removed obsolete environment variable related to API base URL from the Docker configuration.

Copy link
Contributor

coderabbitai bot commented Nov 11, 2024

Walkthrough

This pull request introduces several new constants related to API URLs in the routes.ts file, which are then utilized in other parts of the application. The socket-auth.ts file is updated to use one of these constants instead of an environment variable for constructing API request URLs. The server.ts file removes local definitions of certain constants in favor of imports from routes.ts and eliminates error handling for the API base URL. The server.test.ts file updates import paths and refactors entity names in the tests. Lastly, an environment variable related to API URLs is removed from the Docker environment script.

Changes

File Path Change Summary
app/client/packages/rts/src/constants/routes.ts Added constants: BASE_API_URL, RTS_BASE_PATH, RTS_BASE_API_PATH, RTS_BASE_API_URL, BASE_APPSMITH_API_URL, INTERNAL_BASE_URL.
app/client/packages/rts/src/middlewares/socket-auth.ts Replaced API_BASE_URL with BASE_APPSMITH_API_URL for user info request URL.
app/client/packages/rts/src/server.ts Imported RTS_BASE_PATH and RTS_BASE_API_PATH from @constants/routes; removed error handling for API_BASE_URL.
app/client/packages/rts/src/test/server.test.ts Updated import for RTS_BASE_API_PATH to come from @constants/routes; refactored entity names in tests.
deploy/docker/fs/opt/appsmith/templates/docker.env.sh Removed APPSMITH_API_BASE_URL environment variable definition.

Possibly related PRs

Suggested labels

Bug

Suggested reviewers

  • abhvsn
  • sagar-qa007

🎉 In code we trust, with constants anew,
API paths clearer, our routes now in view.
From local to imports, we streamline the way,
With tests all refactored, let’s code and not stray!
A toast to the changes, let’s celebrate right,
For cleaner configurations, our future is bright! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Nov 11, 2024
@sharat87 sharat87 changed the title chore: Use default value for backend base URL chore: Don't break when Appsmtih API URL isn't set Nov 13, 2024
@sharat87 sharat87 added the ok-to-test Required label for CI label Nov 13, 2024
@sharat87 sharat87 marked this pull request as ready for review November 13, 2024 07:49
@sharat87 sharat87 requested a review from mohanarpit November 13, 2024 07:49
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
app/client/packages/rts/src/middlewares/socket-auth.ts (1)

Line range hint 8-13: Consider creating an issue to track the HTTPS endpoint debugging

The TODO comment identifies a potential improvement to derive API_BASE_URL from the host header, but notes an Axios HTTPS issue blocking this enhancement.

Would you like me to create a GitHub issue to track the investigation of the Axios HTTPS endpoint issue?

app/client/packages/rts/src/test/server.test.ts (2)

Line range hint 14-119: Consider organizing test cases using test.each()

The entityRefactor array contains multiple similar test cases. Consider using Jest's test.each() for better test organization and maintenance.

Example refactor:

const testCases = [
  {
    input: { script: "ApiNever", oldName: "ApiNever", newName: "ApiForever", isJSObject: false },
    expected: { script: "ApiForever", refactorCount: 1 }
  },
  // ... other cases
];

test.each(testCases)('Entity refactor: $input.script', async ({ input, expected }) => {
  const response = await supertest(app)
    .post(`${RTS_BASE_API_PATH}/ast/entity-refactor`)
    .send(input);
  
  expect(response.body.data.script).toEqual(expected.script);
  expect(response.body.data.refactorCount).toEqual(expected.refactorCount);
});

Line range hint 234-252: Consider adding more error test cases

While the syntax error test is good, consider adding tests for:

  • Invalid oldName/newName combinations
  • Empty script strings
  • Malformed input objects

Example additional test:

it("handles empty script input", async () => {
  const request = {
    script: "",
    oldName: "ApiNever",
    newName: "ApiForever",
    isJSObject: true
  };
  
  await supertest(app)
    .post(`${RTS_BASE_API_PATH}/ast/entity-refactor`)
    .send(request)
    .expect(400);
});
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 81c6a1e and f049d46.

📒 Files selected for processing (5)
  • app/client/packages/rts/src/constants/routes.ts (1 hunks)
  • app/client/packages/rts/src/middlewares/socket-auth.ts (2 hunks)
  • app/client/packages/rts/src/server.ts (1 hunks)
  • app/client/packages/rts/src/test/server.test.ts (1 hunks)
  • deploy/docker/fs/opt/appsmith/templates/docker.env.sh (0 hunks)
💤 Files with no reviewable changes (1)
  • deploy/docker/fs/opt/appsmith/templates/docker.env.sh
✅ Files skipped from review due to trivial changes (1)
  • app/client/packages/rts/src/constants/routes.ts
🔇 Additional comments (6)
app/client/packages/rts/src/server.ts (3)

15-15: LGTM! Good centralization of route constants.

Moving route constants to a central location improves maintainability.


Line range hint 44-45: LGTM! Appropriate timeout settings.

The headersTimeout (61s) being slightly higher than keepAliveTimeout (60s) follows best practices for preventing race conditions in connection handling.


15-15: Verify default API URL handling in routes.ts

The removal of API_BASE_URL error handling assumes that routes.ts provides appropriate defaults. Let's verify this assumption.

app/client/packages/rts/src/middlewares/socket-auth.ts (2)

5-5: LGTM! Good move to centralize API URL configuration

The change to import BASE_APPSMITH_API_URL from routes constants aligns well with reducing environment variable dependencies.


38-38: Verify the BASE_APPSMITH_API_URL constant definition

Let's ensure the constant is properly defined with the correct default value.

app/client/packages/rts/src/test/server.test.ts (1)

1-2: LGTM: Import refactor aligns with centralization goal

The change to import RTS_BASE_API_PATH from @constants/routes improves code organization.

@sharat87 sharat87 merged commit 77bae7c into release Nov 15, 2024
47 checks passed
@sharat87 sharat87 deleted the sharat87-patch-3 branch November 15, 2024 08:04
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Nov 20, 2024
We actually don't need the `APPSMITH_API_BASE_URL` variable to be
varying in production ever at all, and the `routes.ts` file already does
have a default for this (on EE). Let's just use that instead of throwing
an impact-less error.

Ideally though, we shouldn't have this env variable at all. Less things
that are configurable, less things that can break other things.

## Automation

/test sanity

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11812221529>
> Commit: f049d46
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11812221529&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`
> Spec:
> <hr>Wed, 13 Nov 2024 07:41:57 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Release Notes

- **New Features**
- Introduced constants for API URLs to streamline endpoint
configurations.

- **Bug Fixes**
- Updated API request URLs to use new constants, ensuring consistency
across the application.

- **Refactor**
	- Centralized route constants to improve maintainability.
- Renamed entities in test cases for clarity while preserving
functionality.

- **Chores**
- Removed obsolete environment variable related to API base URL from the
Docker configuration.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants