Skip to content

Inconsistent request.uri() Behaviour in Dynamic Catch-All Routes #126

Open
@elcharitas

Description

@elcharitas

Problem Description:
I am currently implementing a catch-all route in my project using this runtime. Within the handler for this catch-all route, I need to access the request URI using request.uri().

Issue Details:

  • On the initial page load, everything appears to work as expected. The request.uri() correctly returns the expected path, such as "/hello."
  • However, upon refreshing the page or navigating to a different part of the application, I encounter unexpected behavior. The request.uri() function now returns "/api/[...all]" instead of the expected path as shown in the snippet below:
// api/[...all].rs
use vercel_runtime::{run, Body, Error, Request, Response};

#[tokio::main]
async fn main() -> Result<(), Error> {
    run(handler).await
}

pub async fn handler(req: Request) -> Result<Response<Body>, Error> {
    println!("request.uri, {}", request.uri()); // prints /hello then /api/[...all]
}

This behavior is unexpected and inconsistent, as I would expect request.uri() to consistently return the path of the current request. I have reviewed my vercel configuration and am confident that it's not causing this issue. Here's my vercel.json JIC.

{
  "functions": {
    "api/**/*.rs": {
      "runtime": "vercel-rust@4.0.6"
    }
  },
  "rewrites": [
    {
      "source": "/(.*)",
      "destination": "/api/$1"
    }
  ],
  "redirects": [
    {
      "source": "/",
      "destination": "/home",
      "statusCode": 301
    }
  ]
}

Steps to Reproduce:

  1. Create a catch-all route using the exact snippet above.
  2. Observe the value returned by request.uri().
  3. Refresh the page or navigate to a different route.
  4. Again, observe the value returned by request.uri(), which may now be unexpected.

Expected Behavior:
request.uri() should consistently return the correct path for the current request, regardless of how many times the page is refreshed or navigated.

Environment:

  • Rust version: 1.72
  • Vercel-Rust: 4.0.6

I appreciate any insights or suggestions on resolving this issue. Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions