1a164f9138
--- - Adicionado docker/server.mjs, entry point customizado que monkey-patcha http.createServer antes do Next.js standalone subir, injetando handler de upgrade para fazer pipe TCP de WebSocket (ws://host:3000/websockify?token=...) direto para localhost:6080; - Adicionado src/app/api/novnc/[...path]/route.ts, proxy HTTP dos assets estáticos do noVNC (vnc.html, JS, CSS) para localhost:6080, seguindo o mesmo padrão do proxy HLS; - Corrigido bug de hidratação SSR em src/app/vnc/[id]/page.tsx: URL do iframe agora é computada apenas client-side via useEffect/useState, usando path relativo /api/novnc/ em vez de http://host:6080/; - Atualizado config/supervisord.conf para iniciar Next.js com node /opt/server.mjs; - Atualizado docker/Dockerfile para copiar docker/server.mjs para /opt/server.mjs; ---
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
// Custom entry point: patches http.createServer before Next.js starts,
|
|
// so WebSocket upgrade requests to /websockify are proxied to localhost:6080
|
|
// (noVNC/websockify) without exposing that port publicly.
|
|
import http from "node:http"
|
|
import net from "node:net"
|
|
|
|
const _createServer = http.createServer.bind(http)
|
|
|
|
function attachWebSocketProxy(server) {
|
|
server.on("upgrade", (req, socket, head) => {
|
|
const upstream = net.connect({ host: "127.0.0.1", port: 6080 })
|
|
|
|
upstream.once("connect", () => {
|
|
let raw = `${req.method} ${req.url} HTTP/1.1\r\n`
|
|
for (const [k, v] of Object.entries(req.headers)) {
|
|
raw += `${k}: ${Array.isArray(v) ? v.join(", ") : v}\r\n`
|
|
}
|
|
raw += "\r\n"
|
|
upstream.write(raw)
|
|
if (head?.length) upstream.write(head)
|
|
socket.pipe(upstream)
|
|
upstream.pipe(socket)
|
|
})
|
|
|
|
upstream.on("error", () => { try { socket.destroy() } catch {} })
|
|
socket.on("error", () => { try { upstream.destroy() } catch {} })
|
|
socket.on("close", () => { try { upstream.destroy() } catch {} })
|
|
upstream.on("close", () => { try { socket.destroy() } catch {} })
|
|
})
|
|
}
|
|
|
|
http.createServer = function (...args) {
|
|
const server = _createServer(...args)
|
|
attachWebSocketProxy(server)
|
|
return server
|
|
}
|
|
|
|
await import("/app/server.js")
|