Skip to content

Conversation

@fuegoio
Copy link

@fuegoio fuegoio commented Nov 26, 2025

Hello 👋

I tried the new staticFunctionMiddleware, but I've found an issue as my application is hosted on a subpath (/docs). I propose to fix this, but I'm not sure the router basepath is the right variable to use. Ideally, I would prefer to use the import.meta.env. BASE_URL of Vite, as I think TSR files are quite similar to bundling assets, but I'm not sure it will work.

Let me know what you think and I'll change this straightaway. Thanks for this package!

Summary by CodeRabbit

  • Chores
    • Updated request routing to support environment-configured base paths, enabling the application to function correctly when deployed to non-root server paths.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 26, 2025

Walkthrough

The static function middleware's fetch call now constructs a prefixed URL by joining an environment variable base path (TSS_ROUTER_BASEPATH) with the original URL before making the request. Response handling remains unchanged.

Changes

Cohort / File(s) Summary
URL-Prefixed Fetch Request
packages/start-static-server-functions/src/staticFunctionMiddleware.ts
Modified fetch call to use a base-path-prefixed URL constructed from the TSS_ROUTER_BASEPATH environment variable joined with the original URL, while preserving all downstream response handling logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify correct environment variable name and availability
  • Confirm URL joining logic handles edge cases (trailing slashes, leading slashes)
  • Ensure base path is optional or has proper fallback behavior

Poem

A rabbit hops with glee, 🐰
Base paths now aligned,
Routes flow where they should be,
No more lost to time!
URLs dressed in their finest attire,
This middleware climbs ever higher. 🚀

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add static function middleware support of basepath' clearly summarizes the main change: adding basepath support to the static function middleware.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d7ba00c and 8f4d04e.

📒 Files selected for processing (1)
  • packages/start-static-server-functions/src/staticFunctionMiddleware.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript strict mode with extensive type safety throughout the codebase

Files:

  • packages/start-static-server-functions/src/staticFunctionMiddleware.ts
🔇 Additional comments (1)
packages/start-static-server-functions/src/staticFunctionMiddleware.ts (1)

119-119: Verify that TSS_ROUTER_BASEPATH is properly documented and injected — it is not part of the official TanStack Router API.

Web search confirms that TanStack Router's official approach for basepath configuration is via RouterOptions.basepath (set in code when creating the router), not environment variables. TSS_ROUTER_BASEPATH appears to be a project-specific variable that is not documented in TanStack's official API.

Before merging this change:

  1. Document where and how TSS_ROUTER_BASEPATH is injected — confirm it's set in build config, deployment scripts, or .env files and document that requirement
  2. Remove the non-null assertion — replace process.env.TSS_ROUTER_BASEPATH! with a check that handles the case where the variable is undefined, e.g., process.env.TSS_ROUTER_BASEPATH ?? '' or similar fallback
  3. Consider the official approach — evaluate whether using RouterOptions.basepath (configured at router creation time) would be more maintainable than relying on an undocumented environment variable

Comment on lines +119 to +121
const basePath = process.env.TSS_ROUTER_BASEPATH!
const prefixedUrl = path.join(basePath, url)
result = await fetch(prefixedUrl, {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Use proper URL construction instead of path.join(), and validate the environment variable.

There are several critical issues with this implementation:

  1. Incorrect API: path.join() is for filesystem paths, not URLs. It has OS-specific behavior (e.g., Windows uses backslashes) and doesn't handle URL semantics correctly.

  2. Missing validation: The non-null assertion on process.env.TSS_ROUTER_BASEPATH will cause a runtime error if the variable is undefined, and path.join(undefined, url) will fail.

  3. Type safety: This violates TypeScript strict mode guidelines by using non-null assertion without validation.

Apply this diff to fix the URL construction and add proper validation:

- const basePath = process.env.TSS_ROUTER_BASEPATH!
- const prefixedUrl = path.join(basePath, url)
- result = await fetch(prefixedUrl, {
+ const basePath = process.env.TSS_ROUTER_BASEPATH || ''
+ const prefixedUrl = basePath
+   ? `${basePath.replace(/\/$/, '')}${url}`
+   : url
+ result = await fetch(prefixedUrl, {

Alternatively, if you need more robust URL handling:

- const basePath = process.env.TSS_ROUTER_BASEPATH!
- const prefixedUrl = path.join(basePath, url)
- result = await fetch(prefixedUrl, {
+ const basePath = process.env.TSS_ROUTER_BASEPATH || ''
+ const prefixedUrl = basePath
+   ? new URL(url, new URL(basePath, 'http://dummy')).pathname
+   : url
+ result = await fetch(prefixedUrl, {
📝 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
const basePath = process.env.TSS_ROUTER_BASEPATH!
const prefixedUrl = path.join(basePath, url)
result = await fetch(prefixedUrl, {
const basePath = process.env.TSS_ROUTER_BASEPATH || ''
const prefixedUrl = basePath
? `${basePath.replace(/\/$/, '')}${url}`
: url
result = await fetch(prefixedUrl, {
🤖 Prompt for AI Agents
In packages/start-static-server-functions/src/staticFunctionMiddleware.ts around
lines 119 to 121, the code wrongly uses path.join and non-null assertion for
building the fetch URL; validate that process.env.TSS_ROUTER_BASEPATH is defined
(throw or return a clear error if not), construct the URL using the WHATWG URL
API (e.g., new URL(url, base) or url.resolve equivalent) to correctly combine
base and relative paths, and remove the non-null assertion so TypeScript
enforces the runtime check; ensure the resulting string passed to fetch is a
fully-qualified URL.

@nx-cloud
Copy link

nx-cloud bot commented Nov 26, 2025

View your CI Pipeline Execution ↗ for commit 8f4d04e

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 1m 11s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 7s View ↗

☁️ Nx Cloud last updated this comment at 2025-11-26 11:26:46 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 26, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5970

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5970

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5970

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5970

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5970

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5970

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5970

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5970

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5970

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5970

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5970

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5970

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5970

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5970

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5970

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5970

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5970

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5970

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5970

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5970

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5970

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5970

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5970

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@5970

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5970

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5970

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5970

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5970

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5970

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5970

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5970

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5970

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5970

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5970

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5970

commit: 8f4d04e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant