|
1 | | -import path from 'node:path' |
| 1 | +// import path from 'node:path' |
2 | 2 | import type { IncomingMessage, Server } from 'node:http' |
3 | 3 | import { STATUS_CODES, createServer as createHttpServer } from 'node:http' |
4 | 4 | import type { ServerOptions as HttpsServerOptions } from 'node:https' |
5 | 5 | import { createServer as createHttpsServer } from 'node:https' |
6 | 6 | import type { Socket } from 'node:net' |
7 | 7 | import type { Duplex } from 'node:stream' |
8 | | -import crypto from 'node:crypto' |
| 8 | +// import crypto from 'node:crypto' |
9 | 9 | import colors from 'picocolors' |
10 | 10 | import type { WebSocket as WebSocketRaw } from 'ws' |
11 | 11 | import { WebSocketServer as WebSocketServerRaw_ } from 'ws' |
@@ -102,19 +102,19 @@ function noop() { |
102 | 102 | // |
103 | 103 | // using the query params means the token might be logged out in server or middleware logs |
104 | 104 | // but we assume that is not an issue since the token is regenerated for each process |
105 | | -function hasValidToken(config: ResolvedConfig, url: URL) { |
106 | | - const token = url.searchParams.get('token') |
107 | | - if (!token) return false |
| 105 | +// function hasValidToken(config: ResolvedConfig, url: URL) { |
| 106 | +// const token = url.searchParams.get('token') |
| 107 | +// if (!token) return false |
108 | 108 |
|
109 | | - try { |
110 | | - const isValidToken = crypto.timingSafeEqual( |
111 | | - Buffer.from(token), |
112 | | - Buffer.from(config.webSocketToken), |
113 | | - ) |
114 | | - return isValidToken |
115 | | - } catch {} // an error is thrown when the length is incorrect |
116 | | - return false |
117 | | -} |
| 109 | +// try { |
| 110 | +// const isValidToken = crypto.timingSafeEqual( |
| 111 | +// Buffer.from(token), |
| 112 | +// Buffer.from(config.webSocketToken), |
| 113 | +// ) |
| 114 | +// return isValidToken |
| 115 | +// } catch {} // an error is thrown when the length is incorrect |
| 116 | +// return false |
| 117 | +// } |
118 | 118 |
|
119 | 119 | export function createWebSocketServer( |
120 | 120 | server: HttpServer | null, |
@@ -181,10 +181,10 @@ export function createWebSocketServer( |
181 | 181 |
|
182 | 182 | // If the Origin header is set, this request might be coming from a browser. |
183 | 183 | // Browsers always sets the Origin header for WebSocket connections. |
184 | | - if (req.headers.origin) { |
185 | | - const parsedUrl = new URL(`http://example.com${req.url!}`) |
186 | | - return hasValidToken(config, parsedUrl) |
187 | | - } |
| 184 | + // if (req.headers.origin) { |
| 185 | + // const parsedUrl = new URL(`http://example.com${req.url!}`) |
| 186 | + // return hasValidToken(config, parsedUrl) |
| 187 | + // } |
188 | 188 |
|
189 | 189 | // We allow non-browser requests to connect without a token |
190 | 190 | // for backward compat and convenience |
@@ -213,20 +213,20 @@ export function createWebSocketServer( |
213 | 213 | wss.shouldHandle = shouldHandle |
214 | 214 |
|
215 | 215 | if (wsServer) { |
216 | | - let hmrBase = config.base |
217 | | - const hmrPath = hmr ? hmr.path : undefined |
218 | | - if (hmrPath) { |
219 | | - hmrBase = path.posix.join(hmrBase, hmrPath) |
220 | | - } |
| 216 | + // let hmrBase = config.base |
| 217 | + // const hmrPath = hmr ? hmr.path : undefined |
| 218 | + // if (hmrPath) { |
| 219 | + // hmrBase = path.posix.join(hmrBase, hmrPath) |
| 220 | + // } |
221 | 221 | hmrServerWsListener = (req, socket, head) => { |
222 | 222 | const protocol = req.headers['sec-websocket-protocol']! |
223 | | - const parsedUrl = new URL(`http://example.com${req.url!}`) |
224 | | - if ( |
225 | | - [HMR_HEADER, 'vite-ping'].includes(protocol) && |
226 | | - parsedUrl.pathname === hmrBase |
227 | | - ) { |
| 223 | + // const parsedUrl = new URL(`http://example.com${req.url!}`) |
| 224 | + // if ( |
| 225 | + // [HMR_HEADER, 'vite-ping'].includes(protocol) && |
| 226 | + // parsedUrl.pathname === hmrBase |
| 227 | + // ) { |
228 | 228 | handleUpgrade(req, socket as Socket, head, protocol === 'vite-ping') |
229 | | - } |
| 229 | + // } |
230 | 230 | } |
231 | 231 | wsServer.on('upgrade', hmrServerWsListener) |
232 | 232 | } else { |
|
0 commit comments