-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
vite.middleware
but for WinterCG Request/Response
#15389
Comments
I'm a creator of Hono. We are working on a similar project for Hono. Below is a dev server Vite plugin for Hono and fetch-based applications. https://github.com/honojs/vite-plugins/tree/main/packages/dev-server Whether or not Vite itself will implement these things is a matter of discussion, but for now, try this. |
Hi @yusukebe , I think the I'm wondering if it's possible to expose a The limitation I encountered is with Websockets and mainly because of its forced-way of writing the Entry Point in Dev. It forces you to always do this at the entry point: export default {
fetch: app.fetch,
port: 3000,
}; as well as making sure your In Node In Bun
If there was a import { resolve } from 'node:path';
if (privateConfig.NODE_ENV !== 'production') {
const root = resolve(__dirname, '../..');
// Instantiate Vite's development server and integrate its middleware to our server.
// ⚠️ We should instantiate it *only* in development. (It isn't needed in production
// and would unnecessarily bloat our server in production.)
const vite = await import('vite');
const viteDevMiddleware = (
await vite.createServer({
root,
server: {
middlewareMode: true,
hmr: { port: privateConfig.HMR_PORT },
},
})
).middlewares;
// @ts-ignore
app.use(createViteToHonoMiddleware(viteDevMiddleware)); // 👈 createViteToHonoMiddleware
} And then be able to keep I am basing this on the implementation here: https://github.com/blankeos/express-vike-websockets wherein both HMR and websockets work in a custom express server with Vite. |
Awesome! @yusukebe Let me know if you want to move this discussion elsewhere, but after researching some more, I found that it's actually possible to overcome the limitation I mentioned. (But only on Node). I have recreated the I think a
|
Great Hono has a solution however a WinterCG middleware is still needed for other modern servers like Elysia, H3 (v2), etc.. |
@Blankeos const webHandler = connectToWeb(vite.middlewares)
const response = await webHandler(request)
return response |
Description
https://vitejs.dev/guide/ssr#setting-up-the-dev-server shows how to setup a dev server for ssr using express. with more and more server frameworks moving away from the Node.js Connect style API to be more Request/Response, I wonder if maybe Vite should have middlewares for those applications too?
Suggested solution
or similar to make it compatible with req/res frameworks?
Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: