vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
67.32k stars 6.06k forks source link

Return `contentType` in `transformRequest` #15865

Open nitedani opened 7 months ago

nitedani commented 7 months ago

Description

I would like to use transformRequest for retrieving assets through an rpc connection between a worker and the Vite dev server. My issue is that transformRequest doesn't return the content-type of the result. I need to set the right content-type in the response sent to the browser.

An alternative would be to support passing a standard Request to the vite middlewares, returning a standard Response. https://github.com/vitejs/vite/issues/15389

This is not a blocker. I can always just proxy the requests through http between browser<->worker<->vite.

Suggested solution

Add contentType to the transformRequest return type.

Alternative

Support passing a standard Request to the vite middlewares, returning a standard Response. https://github.com/vitejs/vite/issues/15389

Additional context

No response

Validations

hi-ogawa commented 6 months ago

I think ViteDevServer.transformRequest is meant to return javascript for most of the cases?

https://github.com/vitejs/vite/blob/8b11fea91560c5f084c31aa9b19e64832ac6c3b5/packages/vite/src/node/server/middlewares/transform.ts#L201-L217

I remember there's .css?direct (which I think vike uses?) but this might be the only odd ball which returns text/css content type. If that's the case, then you could check ?direct on your runtime? If that's not the case, then I wonder what's the other possible content types.