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

fix: Not Found issue on direct link access #98

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shivakgurung
Copy link

@shivakgurung shivakgurung commented Oct 23, 2024

This resolves the Not Found issue (#96) on direct page access through links.

Summary by CodeRabbit

  • New Features
    • Introduced a new configuration file to enhance routing for the application.
    • Implemented a rewrite rule to ensure all incoming requests are directed to the main HTML file, supporting single-page application functionality.

Copy link

coderabbitai bot commented Oct 23, 2024

Walkthrough

A new configuration file, vercel.json, has been added to the project. This file includes a rewrites section that establishes a single rewrite rule, directing all incoming requests to the index.html file. This configuration is intended for single-page applications, facilitating client-side routing by ensuring that all routes are managed by the main HTML file.

Changes

File Change Summary
frontend/vercel.json Added new file with rewrites configuration to redirect all requests to index.html.

Poem

In the garden of code, a new path we weave,
vercel.json blooms, oh what a reprieve! 🌼
All routes now lead to the index so bright,
A single-page dance, in the soft moonlight.
Hop along, dear friends, let the routing play,
In this wondrous new world, we’ll frolic and sway! 🐇✨


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.

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

@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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 570059c and bd5d515.

📒 Files selected for processing (1)
  • frontend/vercel.json (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
frontend/vercel.json (2)

1-8: LGTM! This configuration will fix the direct link access issue.

The rewrite rule correctly forwards all requests to index.html, allowing the client-side router to handle the routing properly.


4-5: Verify the impact on API routes.

Ensure that this catch-all rewrite rule doesn't interfere with any API routes if they are hosted on the same domain.

✅ Verification successful

Let me analyze the results and gather more information about the backend API setup to make a conclusive verification.

This will help us understand:

  1. If there are any other vercel.json configurations
  2. How the backend API is set up and if it's on a separate domain

Based on the gathered information, I can now provide a final response as we have sufficient evidence to understand the API setup:

The catch-all rewrite rule in vercel.json is safe for API routes

The codebase shows that:

  • The backend is a separate Express.js application (as seen in backend/src/index.ts)
  • API calls in the frontend code are made to /api/* endpoints
  • The backend appears to be deployed separately, not served from the same Vercel deployment as the frontend

The catch-all rewrite to index.html is safe because:

  1. The backend is a separate service, not affected by frontend's vercel.json
  2. API requests will be handled by your deployment platform's routing before the rewrite rule takes effect
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential API routes that might be affected
rg -g '!node_modules' -g '!build' -g '!dist' "api" --type js --type ts

Length of output: 2213


Script:

#!/bin/bash
# Check vercel.json configurations and backend server setup
fd vercel.json
cat backend/src/index.ts | head -n 50

Length of output: 1220

Comment on lines +2 to +7
"rewrites": [
{
"source": "/(.*)",
"destination": "/index.html"
}
]
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding additional configurations for better production readiness.

While the current configuration solves the core issue, consider these enhancements for better production deployment:

  1. Add exceptions for static assets to prevent unnecessary rewrites
  2. Include security headers
  3. Configure caching rules

Here's an enhanced configuration:

 {
     "rewrites": [
         {
             "source": "/(.*)",
             "destination": "/index.html"
         }
-    ]
+    ],
+    "headers": [
+        {
+            "source": "/(.*)",
+            "headers": [
+                {
+                    "key": "X-Content-Type-Options",
+                    "value": "nosniff"
+                },
+                {
+                    "key": "X-Frame-Options",
+                    "value": "DENY"
+                },
+                {
+                    "key": "X-XSS-Protection",
+                    "value": "1; mode=block"
+                }
+            ]
+        },
+        {
+            "source": "/static/(.*)",
+            "headers": [
+                {
+                    "key": "Cache-Control",
+                    "value": "public, max-age=31536000, immutable"
+                }
+            ]
+        }
+    ]
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"rewrites": [
{
"source": "/(.*)",
"destination": "/index.html"
}
]
"rewrites": [
{
"source": "/(.*)",
"destination": "/index.html"
}
],
"headers": [
{
"source": "/(.*)",
"headers": [
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-Frame-Options",
"value": "DENY"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
}
]
},
{
"source": "/static/(.*)",
"headers": [
{
"key": "Cache-Control",
"value": "public, max-age=31536000, immutable"
}
]
}
]

@nirajacharyaa
Copy link
Member

We are not using Vercel to host our app but we were "previously" using Vercel. We are completely moving out of Vercel into Cloudflare. This PR is out of the project scope. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants