mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 23:33:31 +00:00
[PM-20220] feat: Add support for fd and unix socket bindings (#14262)
* Add support for unix sockets with (unix://) scheme * Add support for listening socket FD (fd+listening:// scheme) * Add support for connected socket FD (fd+connected:// scheme) --------- Co-authored-by: Addison Beck <github@addisonbeck.com>
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
import http from "node:http";
|
||||||
|
import net from "node:net";
|
||||||
|
|
||||||
import * as koaRouter from "@koa/router";
|
import * as koaRouter from "@koa/router";
|
||||||
import { OptionValues } from "commander";
|
import { OptionValues } from "commander";
|
||||||
import * as koa from "koa";
|
import * as koa from "koa";
|
||||||
@@ -50,11 +53,33 @@ export class ServeCommand {
|
|||||||
|
|
||||||
this.serveConfigurator.configureRouter(router);
|
this.serveConfigurator.configureRouter(router);
|
||||||
|
|
||||||
server
|
server.use(router.routes()).use(router.allowedMethods());
|
||||||
.use(router.routes())
|
|
||||||
.use(router.allowedMethods())
|
if (hostname.startsWith("fd+connected://")) {
|
||||||
.listen(port, hostname === "all" ? null : hostname, () => {
|
const fd = parseInt(hostname.slice("fd+connected://".length));
|
||||||
|
const httpServer = http.createServer(server.callback());
|
||||||
|
const socket = new net.Socket({ fd: fd, readable: true, writable: true });
|
||||||
|
// allow idle sockets, incomplete handshakes and slow requests
|
||||||
|
httpServer.keepAliveTimeout = 0;
|
||||||
|
httpServer.headersTimeout = 0;
|
||||||
|
httpServer.timeout = 0;
|
||||||
|
socket.pause();
|
||||||
|
httpServer.emit("connection", socket);
|
||||||
|
socket.resume(); // Let the HTTP parser start reading
|
||||||
|
} else if (hostname.startsWith("fd+listening://")) {
|
||||||
|
const fd = parseInt(hostname.slice("fd+listening://".length));
|
||||||
|
server.listen({ fd }, () => {
|
||||||
|
this.serviceContainer.logService.info("Listening on " + hostname);
|
||||||
|
});
|
||||||
|
} else if (hostname.startsWith("unix://")) {
|
||||||
|
const socketPath = hostname.slice("unix://".length);
|
||||||
|
server.listen(socketPath, () => {
|
||||||
|
this.serviceContainer.logService.info("Listening on " + hostname);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
server.listen(port, hostname === "all" ? null : hostname, () => {
|
||||||
this.serviceContainer.logService.info("Listening on " + hostname + ":" + port);
|
this.serviceContainer.logService.info("Listening on " + hostname + ":" + port);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user