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

fix(vite-plugin-nitro): use proxy to relay requests without api prefix #404

Merged
merged 1 commit into from
May 19, 2023

Conversation

goetzrobin
Copy link
Member

There was an issue that when built for production our nitro server would turn POST requests into GET requests and drop the body. This issue stems from our middleware using $fetch to relay the request with the removed /api prefix. By default, $fetch requests are GET requests and therefore all other requests are converted. So instead of using $fetch directly, we use h3's proxyRequest function to take care of the conversion. We still pass the $fetch.native as our custom fetch implementation as it takes care of figuring out the base URL for us. To make sure that we also test this issue I changed the trpc-app's e2e test to run against the production output. I did the same for the analog-app-e2e-playwright project.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Which package are you modifying?

  • vite-plugin-angular
  • vite-plugin-nitro
  • astro-angular
  • create-analog
  • router
  • platform
  • content
  • nx-plugin
  • trpc

What is the current behavior?

There was an issue that when built for production our nitro server would turn POST requests into GET requests and drop the body.

Issue Number: N/A

What is the new behavior?

Instead of using $fetch directly, we use h3's proxyRequest function to take care of the conversion.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

there was an issue that when built for production our nitro
server would turn POST requests into GET requests and drop
the body. This issue stems from our middleware using $fetch
to relay the request with the removed /api prefix. By default,
$fetch requests are GET requests and therefore all other
requests are converted. So instead of using $fetch directly, we
use h3's proxyRequest function to take care of the conversion.
We still pass the $fetch.native as our custom fetch implementation
as it takes care of figuring out the base URL for us. To make
sure that we also test this issue I changed the trpc-app's e2e
test to run against the production output. I did the same for the
analog-app-e2e-playwright project.
@netlify
Copy link

netlify bot commented May 19, 2023

Deploy Preview for analog-blog ready!

Name Link
🔨 Latest commit 393e93d
🔍 Latest deploy log https://app.netlify.com/sites/analog-blog/deploys/64677d382d8a070008326911
😎 Deploy Preview https://deploy-preview-404--analog-blog.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented May 19, 2023

Deploy Preview for analog-docs ready!

Name Link
🔨 Latest commit 393e93d
🔍 Latest deploy log https://app.netlify.com/sites/analog-docs/deploys/64677d38cfb9e50007a2c7e0
😎 Deploy Preview https://deploy-preview-404--analog-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented May 19, 2023

Deploy Preview for analog-app ready!

Name Link
🔨 Latest commit 393e93d
🔍 Latest deploy log https://app.netlify.com/sites/analog-app/deploys/64677d38b8014900081eb1b1
😎 Deploy Preview https://deploy-preview-404--analog-app.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Member

@brandonroberts brandonroberts left a comment

Choose a reason for hiding this comment

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

🔥

@brandonroberts brandonroberts merged commit 0d74281 into main May 19, 2023
@brandonroberts brandonroberts deleted the fix-nitro-api-middleware branch May 19, 2023 14:49
Villanuevand pushed a commit to Villanuevand/analog that referenced this pull request Sep 12, 2023
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.

2 participants