kliner 0.1.0-beta → 0.1.0-beta.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.
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "kliner",
3
- "version": "0.1.0-beta",
3
+ "version": "0.1.0-beta.1",
4
4
  "description": "Developer-friendly service-worker web proxy framework",
5
5
  "type": "module",
6
- "bin": { "kliner": "bin/cli.js" },
6
+ "bin": {
7
+ "kliner": "bin/cli.js"
8
+ },
7
9
  "main": "./src/server.js",
8
10
  "exports": {
9
11
  ".": "./src/server.js",
@@ -17,7 +19,9 @@
17
19
  "test": "node --test"
18
20
  },
19
21
  "license": "MIT",
20
- "engines": { "node": ">=18.0.0" },
22
+ "engines": {
23
+ "node": ">=18.0.0"
24
+ },
21
25
  "dependencies": {
22
26
  "chalk": "^5.3.0",
23
27
  "commander": "^12.1.0",
@@ -27,6 +31,16 @@
27
31
  "undici": "^6.19.0",
28
32
  "ws": "^8.18.0"
29
33
  },
30
- "devDependencies": { "esbuild": "^0.23.0", "nodemon": "^3.1.0" },
31
- "files": ["bin", "src", "scripts", "templates", "LICENSE", "README.md"]
32
- }
34
+ "devDependencies": {
35
+ "esbuild": "^0.23.0",
36
+ "nodemon": "^3.1.0"
37
+ },
38
+ "files": [
39
+ "bin",
40
+ "src",
41
+ "scripts",
42
+ "templates",
43
+ "LICENSE",
44
+ "README.md"
45
+ ]
46
+ }
package/src/proxy.js CHANGED
@@ -26,7 +26,8 @@ export async function proxyRequest(req, res, config, logger = () => {}) {
26
26
  try {
27
27
  const headers = { ...req.headers };
28
28
  delete headers.host; delete headers.connection; delete headers["content-length"];
29
- const upstream = await request(target, { method: req.method, headers, body: ["GET", "HEAD"].includes(req.method) ? undefined : req, signal: controller.signal, maxRedirections: 5 });
29
+ headers["accept-encoding"] = "identity";
30
+ const upstream = await request(target, { method: req.method, headers, body: ["GET", "HEAD"].includes(req.method) ? undefined : req, signal: controller.signal });
30
31
  logger(req.method, target.href, upstream.statusCode, upstream.headers["content-type"]);
31
32
  for (const [name, value] of Object.entries(upstream.headers)) {
32
33
  if (hopByHop.has(name) || name === "content-length" || name === "content-encoding") continue;
@@ -45,6 +46,7 @@ export async function proxyRequest(req, res, config, logger = () => {}) {
45
46
  res.send(rewriteResponse(body, target.href, type));
46
47
  } else upstream.body.pipe(res);
47
48
  } catch (error) {
49
+ if (config.logging.level === "debug") console.error(error);
48
50
  if (res.headersSent) res.destroy(error);
49
51
  else res.status(error.name === "AbortError" ? 504 : 502).json({ error: error.name === "AbortError" ? "KLINER_TIMEOUT" : "KLINER_TARGET_UNREACHABLE" });
50
52
  } finally { clearTimeout(timeout); }
package/src/server.js CHANGED
@@ -15,6 +15,7 @@ export async function createApp(config) {
15
15
  app.get("/status", (_req, res) => res.json({ status: "ok", allowlist: config.allowlist, servicePath: config.servicePath }));
16
16
  const clientPath = path.dirname(fileURLToPath(import.meta.url));
17
17
  app.get("/kli.js", (_req, res) => res.sendFile(path.join(clientPath, "client", "kli.js")));
18
+ app.use(express.static(path.join(clientPath, "..", "klinerdemo")));
18
19
  app.all(`${config.servicePath}:encoded(*)`, (req, res) => proxyRequest(req, res, config, (method, target, status, type) => {
19
20
  if (config.logging.level !== "silent") console.log(`[${new Date().toISOString().slice(11, 19)}] ${method} ${target} ${status} ${type ?? ""}`);
20
21
  }));