Skip to content

Add api to endpoints #1309

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

Merged
merged 3 commits into from
May 8, 2025
Merged

Conversation

samuel-coutinho
Copy link
Contributor

@samuel-coutinho samuel-coutinho commented May 7, 2025

Describe your changes

Add /api prefix to endpoints.

Write your issue number after "Fixes "

Fixes #1307

Please ensure all items are checked off before requesting a review:

  • I deployed the code locally.
  • I have performed a self-review of my code.
  • I have included the issue # in the PR.
  • I have labelled the PR correctly.
  • The issue I am working on is assigned to me.
  • I didn't use any hardcoded values (otherwise it will not scale, and will make it difficult to maintain consistency across the application).
  • I made sure font sizes, color choices etc are all referenced from the theme.
  • My PR is granular and targeted to one specific feature.
  • I took a screenshot or a video and attached to this PR if there is a UI change.

Summary by CodeRabbit

  • Refactor
    • Updated all API endpoints to be accessible under the "/api" path for improved organization and consistency.
    • Adjusted the application's HTTP request configuration to align with the new "/api" namespace.

@samuel-coutinho samuel-coutinho added this to the 1.0 milestone May 7, 2025
@samuel-coutinho samuel-coutinho self-assigned this May 7, 2025
@samuel-coutinho samuel-coutinho added frontend Frontend related tasks/issues backend Backend related tasks/issues labels May 7, 2025
Copy link
Contributor

coderabbitai bot commented May 7, 2025

"""

Walkthrough

The changes update the API endpoint structure by adding an /api prefix to all backend routes in the Express server and by modifying the Axios client’s base URL to include /api. No other logic, handler, or middleware changes were made, and public interfaces remain unchanged.

Changes

File(s) Change Summary
Clients/src/infrastructure/api/customAxios.ts Updated Axios base URL from ENV_VARs.URL to ${ENV_VARs.URL}/api.
Servers/index.ts Updated all Express routes and the default welcome route to be under the /api namespace.
Servers/swagger.yaml Updated Swagger server URL from http://localhost:3000 to http://localhost:3000/api.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Axios
    participant Server
    participant ExpressRoutes

    Client->>Axios: Make HTTP request (base URL includes /api)
    Axios->>Server: Send request to ${ENV_VARs.URL}/api/...
    Server->>ExpressRoutes: Route request under /api/*
    ExpressRoutes-->>Server: Handle and respond
    Server-->>Axios: Send response
    Axios-->>Client: Return response
Loading

Assessment against linked issues

Objective Addressed Explanation
Add /api/ to API endpoints (#1307)

Poem

A hop and a skip, the endpoints shift,
Now /api gives our routes a lift!
The server and client, in harmony sing,
Unified paths—what joy they bring!
With every request, let’s leap with glee,
For tidy URLs make code-rabbits happy! 🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e11612b and f404ab6.

📒 Files selected for processing (1)
  • Servers/swagger.yaml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Servers/swagger.yaml

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

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

🧹 Nitpick comments (2)
Clients/src/infrastructure/api/customAxios.ts (1)

30-30: Update documentation comment and sanitize baseURL construction

The JSDoc above still refers to REACT_APP_BASE_URL (instead of VITE_APP_API_BASE_URL) and omits the /api prefix. Also, trimming any trailing slash from ENV_VARs.URL will prevent accidental double slashes (//api) if the env var ends with /.

-baseURL: `${ENV_VARs.URL}/api`,
+baseURL: `${ENV_VARs.URL.replace(/\/$/, "")}/api`,
Servers/index.ts (1)

74-95:

❓ Verification inconclusive

Ensure Swagger docs and external references align with /api prefix

All Express routes have been moved under /api, which is correct. Please also:

  1. Update the servers section in swagger.yaml to include /api in the base path.
  2. Confirm any health-check or monitoring endpoints now target /api/*.
  3. Adjust client-side or CI tests that previously hit root-level routes.

Run this script to verify the servers section in swagger.yaml:


🏁 Script executed:

#!/bin/bash
# Locate swagger.yaml and display server URLs for inspection
swagger_file=$(fd --max-depth 1 swagger.yaml | head -n 1)
if [[ -z "$swagger_file" ]]; then
  echo "swagger.yaml not found"
  exit 1
fi
rg -n '"url"' "$swagger_file"

Length of output: 139


🏁 Script executed:

#!/bin/bash
# Search for the swaggerDoc reference in the codebase
rg -n "swaggerDoc" -n .

# List any Swagger/OpenAPI definition files
echo "Possible API spec files:"
fd --extension yaml --extension yml --extension json --type f | grep -Ei 'swagger|openapi'

# For each candidate spec file, show its servers or basePath settings
for spec in $(fd --extension yaml --extension yml --extension json --type f | grep -Ei 'swagger|openapi'); do
  echo "=== Inspecting $spec ==="
  rg -n '"servers"' "$spec" || rg -n 'basePath' "$spec"
done

Length of output: 729


🏁 Script executed:

#!/bin/bash
# Show version and server/basePath details from Servers/swagger.yaml
echo "=== Top 50 lines of Servers/swagger.yaml ==="
head -n 50 Servers/swagger.yaml
echo
echo "=== Searching for host: entries ==="
rg -n 'host:' Servers/swagger.yaml || echo "No host entries found"
echo
echo "=== Searching for basePath: entries ==="
rg -n 'basePath:' Servers/swagger.yaml || echo "No basePath entries found"

Length of output: 1784


Update Swagger server URL to include /api prefix

In Servers/swagger.yaml, the servers block currently reads:

servers:
  - url: http://localhost:3000
    description: Local development server

It should be updated to:

 servers:
-  - url: http://localhost:3000
+  - url: http://localhost:3000/api
     description: Local development server

• Verify any health-check or monitoring endpoints (e.g. /health, /status) have been moved under /api (e.g. /api/health).
• Adjust any client-side or CI tests that still target root-level routes so they call /api/* instead.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a3ab11 and e11612b.

📒 Files selected for processing (2)
  • Clients/src/infrastructure/api/customAxios.ts (1 hunks)
  • Servers/index.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
Clients/src/infrastructure/api/customAxios.ts (1)
Clients/env.vars.ts (1)
  • ENV_VARs (1-4)

Copy link
Collaborator

@MuhammadKhalilzadeh MuhammadKhalilzadeh left a comment

Choose a reason for hiding this comment

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

Thank you @samuel-coutinho

@MuhammadKhalilzadeh MuhammadKhalilzadeh merged commit ac3c9a4 into develop May 8, 2025
2 checks passed
@MuhammadKhalilzadeh MuhammadKhalilzadeh deleted the sam-apr-07-add-api-to-endpoints branch May 8, 2025 09:34
@samuel-coutinho samuel-coutinho restored the sam-apr-07-add-api-to-endpoints branch May 8, 2025 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Backend related tasks/issues frontend Frontend related tasks/issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add /api/ to api endpoints
2 participants