analogjs / analog

The fullstack meta-framework for Angular. Powered by Vite and Nitro
https://analogjs.org
MIT License
2.59k stars 250 forks source link

fix(vite-plugin-nitro): use proxy for API requests instead of custom middleware #1378

Closed brandonroberts closed 1 month ago

brandonroberts commented 1 month ago

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.

Does this PR introduce a breaking change?

Other information

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

netlify[bot] commented 1 month ago

Deploy Preview for analog-docs ready!

Name Link
Latest commit b99e9dedffd10ebeeb42a9b625559d2e26d41577
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.

netlify[bot] commented 1 month ago

Deploy Preview for analog-ng-app ready!

Name Link
Latest commit b99e9dedffd10ebeeb42a9b625559d2e26d41577
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.

netlify[bot] commented 1 month ago

Deploy Preview for analog-app ready!

Name Link
Latest commit b99e9dedffd10ebeeb42a9b625559d2e26d41577
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.

netlify[bot] commented 1 month ago

Deploy Preview for analog-blog ready!

Name Link
Latest commit b99e9dedffd10ebeeb42a9b625559d2e26d41577
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 commented 1 month ago

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

osnoser1 commented 1 month ago

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 😄