Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(nuxt): fix broken external urls when baseURL is set in config #8205

Closed

Conversation

Araneline
Copy link
Contributor

πŸ”— Linked issue

nuxt/nuxt#15082

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Resolves nuxt/nuxt#15082 - set baseURL for ohmyfetch dynamically through interceptor. The urls were prefixed with baseURL even if they were external.

Using onRequest method of ohmyfetch we set a request interceptor which checks for:

  • http(-s) at the beginning of request url
  • not set baseURL in options

If both are true, it sets the baseURL to '' (allowing external link calls). Otherwise if not already in request config - sets the baseURL

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codesandbox
Copy link

codesandbox bot commented Oct 14, 2022

CodeSandbox logoCodeSandbox logoΒ  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@netlify
Copy link

netlify bot commented Oct 14, 2022

βœ… Deploy Preview for nuxt3-docs canceled.

Name Link
πŸ”¨ Latest commit 62a70a1
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/6349ecfabd072c00095085a7

@pi0 pi0 changed the title fix(nuxt): Fix broken external urls when baseURL is set in config fix(nuxt): fix broken external urls when baseURL is set in config Oct 15, 2022
Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

This seems like an upstream bug to me, and we should likely resolve in ufo or ohmyfetch.

Previously we had a similar bug which was resolved in unjs/ufo#68.

-> also posted in https://github.com/nuxt/framework/issues/7983#issuecomment-1279743702

@Araneline
Copy link
Contributor Author

This seems like an upstream bug to me, and we should likely resolve in ufo or ohmyfetch.

Previously we had a similar bug which was resolved in unjs/ufo#68.

-> also posted in nuxt/nuxt#15082

Ok. Would you mind if I had a look at ufo and try to fix it there? Alternatively I can close this PR.

Copy link
Member

danielroe commented Oct 15, 2022

Taking a look upstream would be lovely 😊

@Araneline
Copy link
Contributor Author

Quick update/note: seems like the issue is boiled down to withBase method from ufo which is used if baseURL is set in ohmyfetch.

@Araneline
Copy link
Contributor Author

Araneline commented Oct 15, 2022

@danielroe the fix to that problem was already committed 3 months ago to the unjs/ufo. There was a patch which introduced check for hasProtocol alongside isEmptyURL in withBase function.

Looking at unjs/ohmyfetch repo after pnpm install, it's clear that the old version of the ufo is installed since there's no hasProtocol check.

The solution: update the version of unjs/ufo in unjs/fetch (probably releasing a new version first for ufo).

This branch can be safely disregarded after that.

@danielroe
Copy link
Member

Thanks for investigating. β€οΈπŸ™

@danielroe
Copy link
Member

@pi0 shall i release new versions of ufo and ohmyfetch?

@pi0
Copy link
Member

pi0 commented Oct 15, 2022

ufo@0.8.6 is released. The latest release of ohmyfetch has the compatible semver range dependency on ufo 0.8x. Please try recreating lockfile. It should fix the issue.

@pi0 pi0 closed this Oct 15, 2022
@Araneline Araneline deleted the origin/fix/broken-external-urls branch October 15, 2022 17:00
@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

useFetch/$fetch and external URLs is broken when used in an app configured with a baseUrl
3 participants