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

feat(base-route): Redirecting user on browser to reference path #88

Merged
merged 3 commits into from
Jan 19, 2025

Conversation

rsahyoun
Copy link
Contributor

Description

This PR implements a base route handler middleware that automatically redirects browser-based requests from the root path ("/") to "/reference". The middleware detects common browser user agents and only performs the redirect for browser-based requests, allowing API requests to proceed normally. A list of common browsers was used in the middleware to help distinguish between a user in a browser and a user who is not.

Related Issue

Link to issue #80

Motivation and Context

This change improves the user experience by automatically redirecting browser users to the API reference documentation when they visit the root URL. This ensures that human users find the documentation easily while maintaining the root endpoint's availability.

How Has This Been Tested?

Testing performed:

  • Verified browser detection for popular browsers with Chrome and Microsoft Edge
  • Confirmed redirect behavior when accessing root path via browser
  • Verified API requests (non-browser) still work as expected (Using Postman)
  • Tested that other routes are unaffected by the middleware

Screenshots (if appropriate):

Screenshot 2025-01-19 001624

Screenshot 2025-01-19 001637

Screenshot 2025-01-19 001655

Screenshot 2025-01-19 001708

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code involves a change to the database schema.
  • My code requires a change to the documentation.

@laggycomputer laggycomputer self-requested a review January 19, 2025 08:23
Copy link
Member

@laggycomputer laggycomputer left a comment

Choose a reason for hiding this comment

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

Excellent decision to use middleware. Some minor changes, some of which are more subjective.

apps/api/src/index.ts Outdated Show resolved Hide resolved
apps/api/src/index.ts Outdated Show resolved Hide resolved
apps/api/src/middleware/base-route-handler.ts Outdated Show resolved Hide resolved
apps/api/src/middleware/base-route-handler.ts Outdated Show resolved Hide resolved
…ell as implemented changes recommended by Dante
@rsahyoun rsahyoun force-pushed the feature/base-route-handler branch from 88a9cda to 293dcb4 Compare January 19, 2025 18:39
Copy link
Member

@andrew-wang0 andrew-wang0 left a comment

Choose a reason for hiding this comment

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

Good work!

@andrew-wang0 andrew-wang0 merged commit 23478cd into icssc:main Jan 19, 2025
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.

3 participants