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

useRequestURL() returns double baseUrl on the server side #25763

Closed
sergenux opened this issue Feb 13, 2024 · 0 comments · Fixed by #25765
Closed

useRequestURL() returns double baseUrl on the server side #25763

sergenux opened this issue Feb 13, 2024 · 0 comments · Fixed by #25765

Comments

@sergenux
Copy link

Environment

  • Operating System: Windows_NT
  • Node Version: v20.11.0
  • Nuxt Version: 3.10.1
  • CLI Version: 3.10.0
  • Nitro Version: 2.8.1
  • Package Manager: npm@10.3.0
  • Builder: -
  • User Config: app
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/

Describe the bug

I am trying to use useRequestURL() composable, but it returns different url on the server and client if the baseUrl is set in nuxt config app: { baseURL: "/my-app/" }. On the server, it returns url with path /my-app/my-app/, on the client, it returns the correct url with path /my-app/.
I found source file: nuxt/packages/nuxt/src/app/composables/url.ts:

import { getRequestURL } from 'h3'
import { joinURL } from 'ufo'
import { useRuntimeConfig } from '../nuxt'
import { useRequestEvent } from './ssr'

/** @since 3.5.0 */
export function useRequestURL () {
  if (import.meta.server) {
    const url = getRequestURL(useRequestEvent()!)
    url.pathname = joinURL(useRuntimeConfig().app.baseURL, url.pathname)
    return url
  }
  return new URL(window.location.href)
}

There may be a problem in this line:
url.pathname = joinURL(useRuntimeConfig().app.baseURL, url.pathname)

Additional context

No response

Logs

No response

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

Successfully merging a pull request may close this issue.

2 participants