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 for API requests instead of custom middleware #1378

Merged
merged 2 commits into from
Oct 2, 2024

Conversation

brandonroberts
Copy link
Member

@brandonroberts brandonroberts commented Oct 2, 2024

PR Checklist

Closes #

What is the new behavior?

Introduces the useAPIMiddleware flag for the platform package.

import { defineConfig } from 'vite';
import analog from '@analogjs/platform';

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
  plugins: [analog({
    useAPIMiddleware: false,
  })],

}));

API routes are built under /api during development, and / in the production build, and requests made to /api routes are configured using custom internal middleware. This flag disables the custom internal middleware and uses routeRules to proxy the request instead, which allows the API routes to properly preserve cookies and headers with direct requests and redirects.

  • Existing routeRules configuration is merged with the internal configuration if provided.
  • The prevents a breaking change when used with Cloudflare

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

[optional] What gif best describes this PR or how it makes you feel?

Copy link

netlify bot commented Oct 2, 2024

Deploy Preview for analog-docs ready!

Name Link
🔨 Latest commit b99e9de
🔍 Latest deploy log https://app.netlify.com/sites/analog-docs/deploys/66fd59fef151a900089843c0
😎 Deploy Preview https://deploy-preview-1378--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 configuration.

Copy link

netlify bot commented Oct 2, 2024

Deploy Preview for analog-ng-app ready!

Name Link
🔨 Latest commit b99e9de
🔍 Latest deploy log https://app.netlify.com/sites/analog-ng-app/deploys/66fd59fea7347900071a1312
😎 Deploy Preview https://deploy-preview-1378--analog-ng-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 configuration.

Copy link

netlify bot commented Oct 2, 2024

Deploy Preview for analog-app ready!

Name Link
🔨 Latest commit b99e9de
🔍 Latest deploy log https://app.netlify.com/sites/analog-app/deploys/66fd59fe0951ef000896d7ad
😎 Deploy Preview https://deploy-preview-1378--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 configuration.

Copy link

netlify bot commented Oct 2, 2024

Deploy Preview for analog-blog ready!

Name Link
🔨 Latest commit b99e9de
🔍 Latest deploy log https://app.netlify.com/sites/analog-blog/deploys/66fd59fe4de77700083f080b
😎 Deploy Preview https://deploy-preview-1378--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 configuration.

@andreascorti
Copy link

Thanks a lot @brandonroberts for this fix! Really appreciated!

@brandonroberts brandonroberts merged commit f72087f into beta Oct 2, 2024
23 of 24 checks passed
@brandonroberts brandonroberts deleted the fix-api-proxy branch October 2, 2024 16:33
@osnoser1
Copy link
Contributor

osnoser1 commented Oct 5, 2024

I was checking what was happening with the headers that weren't being set in prod using Vercel for a couple of days. Initially I thought it was a problem with h3 in Vercel, but in the end, I figured out the problem could be in the nitro vite plugin but I hadn't a chance to keep digging.

I really appreciate this fix @brandonroberts, thanks 😄

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.

3 participants