Remove deprecated url.parse() usage from the custom server
Node flags legacy url.parse() (DEP0169) as having security implications and recommends the WHATWG URL API instead. The main request handler's parsedUrl argument to Next's handle() is optional and unused by us, so that call is dropped entirely (matching Next's own minimal custom-server example); the WS upgrade path-check now uses `new URL()` instead. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+2
-3
@@ -1,6 +1,5 @@
|
|||||||
import "./src/bootstrap/async-local-storage-polyfill";
|
import "./src/bootstrap/async-local-storage-polyfill";
|
||||||
import { createServer } from "node:http";
|
import { createServer } from "node:http";
|
||||||
import { parse } from "node:url";
|
|
||||||
import next from "next";
|
import next from "next";
|
||||||
import { WebSocketServer } from "ws";
|
import { WebSocketServer } from "ws";
|
||||||
import { getConfig } from "./src/lib/config/load";
|
import { getConfig } from "./src/lib/config/load";
|
||||||
@@ -25,14 +24,14 @@ const handle = app.getRequestHandler();
|
|||||||
|
|
||||||
app.prepare().then(() => {
|
app.prepare().then(() => {
|
||||||
const httpServer = createServer((req, res) => {
|
const httpServer = createServer((req, res) => {
|
||||||
handle(req, res, parse(req.url ?? "/", true));
|
handle(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
const wss = new WebSocketServer({ noServer: true });
|
const wss = new WebSocketServer({ noServer: true });
|
||||||
attachWsServer(wss);
|
attachWsServer(wss);
|
||||||
|
|
||||||
httpServer.on("upgrade", (req, socket, head) => {
|
httpServer.on("upgrade", (req, socket, head) => {
|
||||||
const { pathname } = parse(req.url ?? "/");
|
const { pathname } = new URL(req.url ?? "/", "http://internal");
|
||||||
if (pathname !== "/ws/runs") {
|
if (pathname !== "/ws/runs") {
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user