Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/plugin-vite/src/plugins/dev_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ export function devServer(): Plugin[] {
configureServer(server) {
const IGNORE_URLS = /^\/(@(vite|fs|id)|\.vite)\//;

server.httpServer?.on("deno:request", (ev) => {
const { headers } = ev.req;
if (
headers.get("upgrade") !== "websocket" ||
// Vite uses websockets with protocol set to vite-hmr, vite-ping
headers.get("sec-websocket-protocol")?.startsWith("vite-")
) {
Comment on lines +20 to +24
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish every non-vite request was going through this route, as the current implementation looks too fragile

It is however only required and used for websocket for now.

return;
}
// When pendingResponse is set, rest of the handlers won't fire for any request, so websocket requests
// are going straight to the fresh server.
ev.pendingResponse = server.ssrLoadModule("fresh:server_entry").then(
(mod) => mod.default.fetch(ev.req) as Promise<Response>,
);
});

server.middlewares.use(async (nodeReq, nodeRes, next) => {
const serverCfg = server.config.server;

Expand Down
Loading