procdeck 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +37 -11
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -47042,14 +47042,29 @@ var WsMessageParser = class {
47042
47042
  };
47043
47043
 
47044
47044
  // src/interpose.ts
47045
- var upstreamOptions = (req, port) => ({
47046
- host: "localhost",
47047
- port,
47048
- autoSelectFamily: true,
47049
- method: req.method,
47050
- path: req.url,
47051
- headers: { ...req.headers, host: `localhost:${port}` }
47052
- });
47045
+ var upstreamOptions = (req, port) => {
47046
+ const headers = {
47047
+ ...req.headers,
47048
+ host: `localhost:${port}`
47049
+ };
47050
+ if (headers["x-forwarded-host"] === void 0 && req.headers.host !== void 0) {
47051
+ headers["x-forwarded-host"] = req.headers.host;
47052
+ }
47053
+ if (headers["x-forwarded-proto"] === void 0) headers["x-forwarded-proto"] = "http";
47054
+ const client = req.socket.remoteAddress;
47055
+ if (client !== void 0) {
47056
+ const prior = headers["x-forwarded-for"];
47057
+ headers["x-forwarded-for"] = prior === void 0 ? client : `${String(prior)}, ${client}`;
47058
+ }
47059
+ return {
47060
+ host: "localhost",
47061
+ port,
47062
+ autoSelectFamily: true,
47063
+ method: req.method,
47064
+ path: req.url,
47065
+ headers
47066
+ };
47067
+ };
47053
47068
  var forwardRequest = (options) => {
47054
47069
  const { port, record: record2, req, res } = options;
47055
47070
  const started = Date.now();
@@ -47077,17 +47092,27 @@ var forwardRequest = (options) => {
47077
47092
  const resTap = record2 === void 0 ? void 0 : new BodyTap(isTextType(upRes.headers["content-type"]));
47078
47093
  if (resTap !== void 0) upRes.on("data", (chunk) => resTap.push(chunk));
47079
47094
  upRes.on("end", () => finish(upRes.statusCode ?? 502, resTap, redactHeaders2(upRes.headers)));
47080
- upRes.on("close", () => finish(upRes.statusCode ?? 502, resTap, redactHeaders2(upRes.headers)));
47095
+ upRes.on("close", () => {
47096
+ finish(upRes.statusCode ?? 502, resTap, redactHeaders2(upRes.headers));
47097
+ if (!res.writableEnded) res.destroy();
47098
+ });
47081
47099
  res.writeHead(upRes.statusCode ?? 502, upRes.headers);
47082
47100
  upRes.pipe(res);
47083
47101
  });
47084
47102
  upstream.on("error", () => {
47085
47103
  finish(0);
47104
+ if (res.destroyed) return;
47105
+ if (res.headersSent) return res.destroy();
47086
47106
  if (options.onError !== void 0) return options.onError(res);
47087
- if (!res.headersSent) res.writeHead(502, { "content-type": "text/plain; charset=utf-8" });
47107
+ res.writeHead(502, { "content-type": "text/plain; charset=utf-8" });
47088
47108
  res.end(`procdeck: upstream refused the connection on :${port}
47089
47109
  `);
47090
47110
  });
47111
+ res.on("close", () => {
47112
+ if (res.writableEnded) return;
47113
+ upstream.destroy();
47114
+ finish(0);
47115
+ });
47091
47116
  req.pipe(upstream);
47092
47117
  };
47093
47118
  var nextConnId = 1;
@@ -48011,7 +48036,8 @@ var hostProcId = (host) => {
48011
48036
  return name.endsWith(".localhost") ? name.slice(0, -".localhost".length) : void 0;
48012
48037
  };
48013
48038
  var refuse = (res, status2, message) => {
48014
- if (!res.headersSent) res.writeHead(status2, { "content-type": "text/plain; charset=utf-8" });
48039
+ if (res.headersSent) return void res.destroy();
48040
+ res.writeHead(status2, { "content-type": "text/plain; charset=utf-8" });
48015
48041
  res.end(`procdeck: ${message}
48016
48042
  `);
48017
48043
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "procdeck",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Interactive dev-process multiplexer with a web UI: terminal panes in a browser tab, declarative dependencies, assigned ports and a *.localhost reverse proxy.",
5
5
  "keywords": [
6
6
  "cli",