-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Support custom middleware for preview server #3788
Comments
Another use case for this change: My application relies on SharedArrayBuffer support. For security reasons, two headers need to be sent on every response:
I'm using a plugin which adds a dev server middleware that send the headers with every response. However, when testing the app using Allowing custom middleware for the preview server would be a great help with testing the application. |
me too |
We've been using CRA with
Being able to access that |
#7658 implements |
An update: before any new versions of Vite, I tried another way to walk-around, which is creating another mock server at the same time in another port (e.g. 8081), then proxy all the paths you mocked in the Vite preview server. And it works so far. So like:
But anyway, still looking forward to the official better solution. Thanks. |
Clear and concise description of the problem
I'd like to customize some high-level proxy/mock logic on the preview server. Currently, it only supports cors and proxy configuration, which seems limited to achieve this.
Suggested solution
To better support this, I'd like to add one more Vite-specific hook named
configurePreviewServer
, which could be run before the preview server is open to access.The API design and behavior could be similar to
configureServer
, which accept aserver
parameter.Alternative
Just use
configureServer
, but at the same time, add one more field toViteDevServer
to identify whether server mode isdev
orpreview
. So the plugin author could give different logics in different modes.Additional context
The text was updated successfully, but these errors were encountered: