kn-http-server 0.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.
- package/dist/public/favicon.ico +0 -0
- package/dist/public/index.html +20 -0
- package/dist/public/script.js +14 -0
- package/dist/public/style.css +16 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +88 -0
- package/dist/server.js.map +1 -0
- package/dist/utils/argshandler.d.ts +2 -0
- package/dist/utils/argshandler.d.ts.map +1 -0
- package/dist/utils/argshandler.js +20 -0
- package/dist/utils/argshandler.js.map +1 -0
- package/dist/utils/dirpath.d.ts +3 -0
- package/dist/utils/dirpath.d.ts.map +1 -0
- package/dist/utils/dirpath.js +12 -0
- package/dist/utils/dirpath.js.map +1 -0
- package/dist/utils/ffmpeg.d.ts +2 -0
- package/dist/utils/ffmpeg.d.ts.map +1 -0
- package/dist/utils/ffmpeg.js +116 -0
- package/dist/utils/ffmpeg.js.map +1 -0
- package/dist/utils/mime.d.ts +2 -0
- package/dist/utils/mime.d.ts.map +1 -0
- package/dist/utils/mime.js +108 -0
- package/dist/utils/mime.js.map +1 -0
- package/package.json +26 -0
- package/readme.md +89 -0
|
Binary file
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<link rel="stylesheet" href="style.css" />
|
|
7
|
+
<title>Index</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<h1>Files in Directory: - ${DynamicFolder}</h1>
|
|
11
|
+
|
|
12
|
+
<div id="dirs" data-="">
|
|
13
|
+
<ol>
|
|
14
|
+
${DynamicHTML}
|
|
15
|
+
</ol>
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
<script src="script.js" , type="module"></script>
|
|
19
|
+
</body>
|
|
20
|
+
</html>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// console.log("hii html")
|
|
2
|
+
|
|
3
|
+
// document.documentElement.style.background = "blue";
|
|
4
|
+
// or
|
|
5
|
+
// document.body.style.background = "pink";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
// Dynamic Element from js
|
|
9
|
+
const el = document.createElement("div");
|
|
10
|
+
el.textContent = "test";
|
|
11
|
+
// el.id = "ce"
|
|
12
|
+
el.style.background = "blue"
|
|
13
|
+
|
|
14
|
+
document.body.appendChild(el);
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":""}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { open, readdir, readFile } from "node:fs/promises";
|
|
3
|
+
import http from "node:http";
|
|
4
|
+
import { mime } from "./utils/mime.js";
|
|
5
|
+
import { createApath } from "./utils/dirpath.js";
|
|
6
|
+
import { argsHandler } from "./utils/argshandler.js";
|
|
7
|
+
const server = http.createServer();
|
|
8
|
+
let port = 3000;
|
|
9
|
+
let addr = "0.0.0.0";
|
|
10
|
+
let highwaterMark;
|
|
11
|
+
argsHandler("-p", (portNum) => {
|
|
12
|
+
if (!portNum || isNaN(Number(portNum))) {
|
|
13
|
+
throw Error("Invalid port number after -p");
|
|
14
|
+
}
|
|
15
|
+
port = Number(portNum);
|
|
16
|
+
});
|
|
17
|
+
argsHandler("-a", (ipAddr) => {
|
|
18
|
+
if (!ipAddr) {
|
|
19
|
+
throw Error("Invalid IP address after -a");
|
|
20
|
+
}
|
|
21
|
+
addr = ipAddr;
|
|
22
|
+
});
|
|
23
|
+
argsHandler("-hw", (hw) => {
|
|
24
|
+
if (!hw || isNaN(Number(hw))) {
|
|
25
|
+
throw Error("Invalid highwater mark number after -hw");
|
|
26
|
+
}
|
|
27
|
+
if (Number(hw) < 1 || Number(hw) > 1024 * 1024 * 1024) {
|
|
28
|
+
throw Error("Highwater mark must be between 1 and 1073741824");
|
|
29
|
+
}
|
|
30
|
+
highwaterMark = Number(hw);
|
|
31
|
+
});
|
|
32
|
+
server.on("request", async (req, res) => {
|
|
33
|
+
let [url, query] = (req.url || "/").split("?");
|
|
34
|
+
url = decodeURIComponent(url || "/");
|
|
35
|
+
console.log(url, "and", query);
|
|
36
|
+
if (url == "/favicon.ico") {
|
|
37
|
+
const favicon = await readFile(createApath("../", "public", "favicon.ico"));
|
|
38
|
+
res.setHeader("Content-Type", "image/x-icon");
|
|
39
|
+
return res.end(favicon);
|
|
40
|
+
// console.clear();
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const fh = await open(`.${url}`);
|
|
44
|
+
const stat = await fh.stat();
|
|
45
|
+
const contentType = mime(url);
|
|
46
|
+
if (stat.isDirectory()) {
|
|
47
|
+
console.log(createApath("../", "public", "index.html"));
|
|
48
|
+
const htmlContent = await readFile(createApath("../", "public", "index.html"));
|
|
49
|
+
const dirsList = await readdir(`.${url}`);
|
|
50
|
+
let DynamicHTML = "";
|
|
51
|
+
let DynamicFolder = url;
|
|
52
|
+
dirsList.forEach((item, index) => {
|
|
53
|
+
// dirsList[index] = `<li>${item}</li>`;
|
|
54
|
+
DynamicHTML += `<li><a href="${url === "/" ? "" : url}/${item}"> ${item}</a> <a href="${url === "/" ? "" : url}/${item}?preview"> 👁️</a> <a href="${url === "/" ? "" : url}/${item}?download"> ⬇️</a></li>`;
|
|
55
|
+
});
|
|
56
|
+
if (query === "download") {
|
|
57
|
+
res.setHeader("content-disposition", "attachment");
|
|
58
|
+
// res.setHeader("Content-Type", `${contentType}`);
|
|
59
|
+
}
|
|
60
|
+
res.end(htmlContent
|
|
61
|
+
.toString()
|
|
62
|
+
.replace("${DynamicHTML}", DynamicHTML)
|
|
63
|
+
.replace("${DynamicFolder}", DynamicFolder));
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
res.setHeader("Content-Type", `${contentType}`);
|
|
67
|
+
if (query === "download") {
|
|
68
|
+
res.setHeader("content-disposition", "attachment");
|
|
69
|
+
// res.setHeader("filename", "a.txt")
|
|
70
|
+
}
|
|
71
|
+
res.setHeader("Content-length", `${stat.size}`);
|
|
72
|
+
const rs = fh.createReadStream({
|
|
73
|
+
highWaterMark: highwaterMark ? Number(highwaterMark) : undefined,
|
|
74
|
+
});
|
|
75
|
+
rs.pipe(res);
|
|
76
|
+
}
|
|
77
|
+
res.on("close", () => {
|
|
78
|
+
fh.close();
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
res.end(err.message);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
server.listen(port, addr, () => {
|
|
86
|
+
console.log(`API listening on http://${addr}:${port}`);
|
|
87
|
+
});
|
|
88
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;AAEnC,IAAI,IAAI,GAAW,IAAI,CAAC;AACxB,IAAI,IAAI,GAAW,SAAS,CAAC;AAC7B,IAAI,aAAqB,CAAC;AAE1B,WAAW,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE;IAC5B,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;Q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
|
1
|
+
{"version":3,"file":"argshandler.d.ts","sourceRoot":"","sources":["../../src/utils/argshandler.ts"],"names":[],"mappings":"AACA,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,QAQhF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function argsHandler(flag, cb) {
|
|
2
|
+
const args = process.argv.slice(2).filter(Boolean);
|
|
3
|
+
if (args.includes(flag)) {
|
|
4
|
+
const flagValue = args[args.indexOf(flag) + 1];
|
|
5
|
+
cb(flagValue);
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
// return false;
|
|
9
|
+
}
|
|
10
|
+
// for node utils/argshandler p=1000 ip=10.25.23.36 like this usage
|
|
11
|
+
// function argsObjConverter() {
|
|
12
|
+
// const args = process.argv.slice(2);
|
|
13
|
+
// const argsObj: Record<string, string | undefined> = {};
|
|
14
|
+
// args.forEach((arg) => {
|
|
15
|
+
// const [key, value] = arg.split("=");
|
|
16
|
+
// argsObj[key] = value;
|
|
17
|
+
// });
|
|
18
|
+
// return argsObj;
|
|
19
|
+
// }
|
|
20
|
+
//# sourceMappingURL=argshandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"argshandler.js","sourceRoot":"","sources":["../../src/utils/argshandler.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,EAAuC;IAC7E,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACnD,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAC/C,EAAE,CAAC,SAAS,CAAC,CAAC;QACd,OAAM;IACV,CAAC;IACD,gBAAgB;AACpB,CAAC;AAGD,mEAAmE;AACnE,gCAAgC;AAChC,wCAAwC;AACxC,4DAA4D;AAC5D,4BAA4B;AAC5B,2CAA2C;AAC3C,4BAA4B;AAC5B,QAAQ;AACR,oBAAoB;AACpB,IAAI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dirpath.d.ts","sourceRoot":"","sources":["../../src/utils/dirpath.ts"],"names":[],"mappings":"AAGA,wBAAgB,WAAW,CAAC,GAAG,SAAS,EAAE,MAAM,EAAE,UAGjD;AAGD,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,UAGzC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
//create absolute path
|
|
3
|
+
export function createApath(...filePaths) {
|
|
4
|
+
const dir = path.join(import.meta.dirname, ...filePaths);
|
|
5
|
+
return dir;
|
|
6
|
+
}
|
|
7
|
+
//join relative path
|
|
8
|
+
export function joinRpath(filePath) {
|
|
9
|
+
const dirn = path.join(process.cwd(), filePath);
|
|
10
|
+
return dirn;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=dirpath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dirpath.js","sourceRoot":"","sources":["../../src/utils/dirpath.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,sBAAsB;AACtB,MAAM,UAAU,WAAW,CAAC,GAAG,SAAmB;IAChD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,CAAC;IACzD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,oBAAoB;AACpB,MAAM,UAAU,SAAS,CAAC,QAAgB;IACxC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;IAChD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ffmpeg.d.ts","sourceRoot":"","sources":["../../src/utils/ffmpeg.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// import { open, readdir, readFile } from "node:fs/promises";
|
|
2
|
+
// import { createReadStream } from "node:fs";
|
|
3
|
+
// import { spawn } from "node:child_process";
|
|
4
|
+
// import http from "node:http";
|
|
5
|
+
// import { MIMEParams, MIMEType } from "node:util";
|
|
6
|
+
// import { mime } from "./mime.js";
|
|
7
|
+
// const server = http.createServer();
|
|
8
|
+
export {};
|
|
9
|
+
// const port = 3000;
|
|
10
|
+
// const ip = "0.0.0.0";
|
|
11
|
+
// server.on("request", async (req, res) => {
|
|
12
|
+
// let [url, query] = req.url.split("?");
|
|
13
|
+
// url = decodeURIComponent(url);
|
|
14
|
+
// console.log(url, "and", query);
|
|
15
|
+
// if (url == "/favicon.ico") return res.end("no favicon");
|
|
16
|
+
// // console.clear();
|
|
17
|
+
// try {
|
|
18
|
+
// const fh = await open(`.${url}`);
|
|
19
|
+
// const stat = await fh.stat();
|
|
20
|
+
// // const contentType = mime.lookup(url);
|
|
21
|
+
// const contentType = mime(url);
|
|
22
|
+
// if (stat.isDirectory()) {
|
|
23
|
+
// const htmlContent = await readFile("./public/index.html");
|
|
24
|
+
// const dirsList = await readdir(`.${url}`);
|
|
25
|
+
// let DynamicHTML = "";
|
|
26
|
+
// let DynamicFolder = url;
|
|
27
|
+
// dirsList.forEach((item, index) => {
|
|
28
|
+
// // dirsList[index] = `<li>${item}</li>`;
|
|
29
|
+
// DynamicHTML += `<li><a href="${
|
|
30
|
+
// url === "/" ? "" : url
|
|
31
|
+
// }/${item}"> ${item}</a> <a href="${
|
|
32
|
+
// url === "/" ? "" : url
|
|
33
|
+
// }/${item}?preview"> 👁️</a> <a href="${
|
|
34
|
+
// url === "/" ? "" : url
|
|
35
|
+
// }/${item}?download"> ⬇️</a></li>`;
|
|
36
|
+
// });
|
|
37
|
+
// if (query === "download") {
|
|
38
|
+
// res.setHeader("content-disposition", "attachment");
|
|
39
|
+
// // res.setHeader("Content-Type", `${contentType}`);
|
|
40
|
+
// }
|
|
41
|
+
// res.end(
|
|
42
|
+
// htmlContent
|
|
43
|
+
// .toString()
|
|
44
|
+
// .replace("${DynamicHTML}", DynamicHTML)
|
|
45
|
+
// .replace("${DynamicFolder}", DynamicFolder)
|
|
46
|
+
// );
|
|
47
|
+
// } else {
|
|
48
|
+
// const ext = url.split(".").pop()?.toLowerCase();
|
|
49
|
+
// const filePath = `.${url}`;
|
|
50
|
+
// if (query === "preview" && ext === "mkv") {
|
|
51
|
+
// res.statusCode = 200;
|
|
52
|
+
// res.setHeader("Content-Type", "video/mp4");
|
|
53
|
+
// res.setHeader("Accept-Ranges", "bytes");
|
|
54
|
+
// const ffmpeg = spawn("ffmpeg", [
|
|
55
|
+
// "-i",
|
|
56
|
+
// filePath,
|
|
57
|
+
// "-f",
|
|
58
|
+
// "mp4",
|
|
59
|
+
// "-movflags",
|
|
60
|
+
// "frag_keyframe+empty_moov",
|
|
61
|
+
// "-vcodec",
|
|
62
|
+
// "libx264",
|
|
63
|
+
// "-acodec",
|
|
64
|
+
// "aac",
|
|
65
|
+
// "-preset",
|
|
66
|
+
// "veryfast",
|
|
67
|
+
// "-crf",
|
|
68
|
+
// "23",
|
|
69
|
+
// "-pix_fmt",
|
|
70
|
+
// "yuv420p",
|
|
71
|
+
// "-g",
|
|
72
|
+
// "48",
|
|
73
|
+
// "-r",
|
|
74
|
+
// "30",
|
|
75
|
+
// "pipe:1",
|
|
76
|
+
// ]);
|
|
77
|
+
// ffmpeg.stdout.pipe(res);
|
|
78
|
+
// ffmpeg.stderr.on("data", () => {});
|
|
79
|
+
// const killFfmpeg = () => ffmpeg.kill("SIGKILL");
|
|
80
|
+
// res.on("close", killFfmpeg);
|
|
81
|
+
// res.on("finish", killFfmpeg);
|
|
82
|
+
// return;
|
|
83
|
+
// }
|
|
84
|
+
// res.setHeader("Content-Type", `${contentType}`);
|
|
85
|
+
// if (query === "download") {
|
|
86
|
+
// res.setHeader("content-disposition", "attachment");
|
|
87
|
+
// // res.setHeader("filename", "a.txt")
|
|
88
|
+
// }
|
|
89
|
+
// const range = req.headers.range;
|
|
90
|
+
// if (range) {
|
|
91
|
+
// const [startStr, endStr] = range.replace(/bytes=/, "").split("-");
|
|
92
|
+
// const start = Number.parseInt(startStr, 10);
|
|
93
|
+
// const end = endStr ? Number.parseInt(endStr, 10) : stat.size - 1;
|
|
94
|
+
// const chunkSize = end - start + 1;
|
|
95
|
+
// res.statusCode = 206;
|
|
96
|
+
// res.setHeader("Content-Range", `bytes ${start}-${end}/${stat.size}`);
|
|
97
|
+
// res.setHeader("Accept-Ranges", "bytes");
|
|
98
|
+
// res.setHeader("Content-Length", `${chunkSize}`);
|
|
99
|
+
// createReadStream(filePath, { start, end }).pipe(res);
|
|
100
|
+
// } else {
|
|
101
|
+
// res.setHeader("Content-length", `${stat.size}`);
|
|
102
|
+
// const rs = fh.createReadStream();
|
|
103
|
+
// rs.pipe(res);
|
|
104
|
+
// }
|
|
105
|
+
// }
|
|
106
|
+
// res.on("close", () => {
|
|
107
|
+
// fh.close();
|
|
108
|
+
// });
|
|
109
|
+
// } catch (err: any) {
|
|
110
|
+
// res.end(err.message);
|
|
111
|
+
// }
|
|
112
|
+
// });
|
|
113
|
+
// server.listen(port, ip, () => {
|
|
114
|
+
// console.log(`API listening on http://${ip}:${port}`);
|
|
115
|
+
// });
|
|
116
|
+
//# sourceMappingURL=ffmpeg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ffmpeg.js","sourceRoot":"","sources":["../../src/utils/ffmpeg.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,8CAA8C;AAC9C,8CAA8C;AAC9C,gCAAgC;AAChC,oDAAoD;AACpD,oCAAoC;AACpC,sCAAsC;;AAE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,6CAA6C;AAE7C,gCAAgC;AAChC,gFAAgF;AAChF,mDAAmD;AACnD,2DAA2D;AAC3D,gEAAgE;AAChE,iBAAiB;AACjB,2DAA2D;AAC3D,4CAA4C;AAC5C,wBAAwB;AACxB,UAAU;AACV,QAAQ;AAER,8BAA8B;AAC9B,oBAAoB;AACpB,UAAU;AACV,yBAAyB;AACzB,4BAA4B;AAC5B,MAAM;AACN,MAAM;AAEN,kCAAkC;AAClC,0DAA0D;AAC1D,MAAM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mime.d.ts","sourceRoot":"","sources":["../../src/utils/mime.ts"],"names":[],"mappings":"AA4GA,wBAAgB,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAI7C"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
const extensionToMime = new Map([
|
|
2
|
+
// Text
|
|
3
|
+
["txt", "text/plain; charset=utf-8"],
|
|
4
|
+
["text", "text/plain; charset=utf-8"],
|
|
5
|
+
["csv", "text/csv; charset=utf-8"],
|
|
6
|
+
["tsv", "text/tab-separated-values; charset=utf-8"],
|
|
7
|
+
["md", "text/markdown; charset=utf-8"],
|
|
8
|
+
["html", "text/html; charset=utf-8"],
|
|
9
|
+
["htm", "text/html; charset=utf-8"],
|
|
10
|
+
["css", "text/css; charset=utf-8"],
|
|
11
|
+
["js", "text/javascript; charset=utf-8"],
|
|
12
|
+
["mjs", "text/javascript; charset=utf-8"],
|
|
13
|
+
["cjs", "text/javascript; charset=utf-8"],
|
|
14
|
+
["json", "application/json; charset=utf-8"],
|
|
15
|
+
["map", "application/json; charset=utf-8"],
|
|
16
|
+
["xml", "application/xml; charset=utf-8"],
|
|
17
|
+
["yaml", "text/yaml; charset=utf-8"],
|
|
18
|
+
["yml", "text/yaml; charset=utf-8"],
|
|
19
|
+
["svg", "image/svg+xml"],
|
|
20
|
+
["srt", "application/x-subrip; charset=utf-8"],
|
|
21
|
+
// Images
|
|
22
|
+
["png", "image/png"],
|
|
23
|
+
["jpg", "image/jpeg"],
|
|
24
|
+
["jpeg", "image/jpeg"],
|
|
25
|
+
["gif", "image/gif"],
|
|
26
|
+
["webp", "image/webp"],
|
|
27
|
+
["avif", "image/avif"],
|
|
28
|
+
["ico", "image/x-icon"],
|
|
29
|
+
["bmp", "image/bmp"],
|
|
30
|
+
["tif", "image/tiff"],
|
|
31
|
+
["tiff", "image/tiff"],
|
|
32
|
+
["heic", "image/heic"],
|
|
33
|
+
["heif", "image/heif"],
|
|
34
|
+
["dng", "image/x-adobe-dng"],
|
|
35
|
+
["cr2", "image/x-canon-cr2"],
|
|
36
|
+
["cr3", "image/x-canon-cr3"],
|
|
37
|
+
["nef", "image/x-nikon-nef"],
|
|
38
|
+
["arw", "image/x-sony-arw"],
|
|
39
|
+
["raf", "image/x-fuji-raf"],
|
|
40
|
+
["rw2", "image/x-panasonic-rw2"],
|
|
41
|
+
["orf", "image/x-olympus-orf"],
|
|
42
|
+
// Audio
|
|
43
|
+
["mp3", "audio/mpeg"],
|
|
44
|
+
["wav", "audio/wav"],
|
|
45
|
+
["aac", "audio/aac"],
|
|
46
|
+
["flac", "audio/flac"],
|
|
47
|
+
["ogg", "audio/ogg"],
|
|
48
|
+
["opus", "audio/opus"],
|
|
49
|
+
["m4a", "audio/mp4"],
|
|
50
|
+
["wma", "audio/x-ms-wma"],
|
|
51
|
+
["alac", "audio/alac"],
|
|
52
|
+
["aiff", "audio/aiff"],
|
|
53
|
+
["ape", "audio/ape"],
|
|
54
|
+
["amr", "audio/amr"],
|
|
55
|
+
// Video
|
|
56
|
+
["mp4", "video/mp4"],
|
|
57
|
+
["m4v", "video/x-m4v"],
|
|
58
|
+
["mkv", "video/x-matroska"],
|
|
59
|
+
["mov", "video/quicktime"],
|
|
60
|
+
["avi", "video/x-msvideo"],
|
|
61
|
+
["webm", "video/webm"],
|
|
62
|
+
["flv", "video/x-flv"],
|
|
63
|
+
["wmv", "video/x-ms-wmv"],
|
|
64
|
+
["3gp", "video/3gpp"],
|
|
65
|
+
["ts", "video/mp2t"],
|
|
66
|
+
["mts", "video/mp2t"],
|
|
67
|
+
["vob", "video/dvd"],
|
|
68
|
+
// Documents
|
|
69
|
+
["pdf", "application/pdf"],
|
|
70
|
+
["doc", "application/msword"],
|
|
71
|
+
[
|
|
72
|
+
"docx",
|
|
73
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
74
|
+
],
|
|
75
|
+
["xls", "application/vnd.ms-excel"],
|
|
76
|
+
["xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
|
|
77
|
+
["ppt", "application/vnd.ms-powerpoint"],
|
|
78
|
+
[
|
|
79
|
+
"pptx",
|
|
80
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
81
|
+
],
|
|
82
|
+
["rtf", "application/rtf"],
|
|
83
|
+
["odt", "application/vnd.oasis.opendocument.text"],
|
|
84
|
+
["ods", "application/vnd.oasis.opendocument.spreadsheet"],
|
|
85
|
+
["odp", "application/vnd.oasis.opendocument.presentation"],
|
|
86
|
+
// Archives
|
|
87
|
+
["zip", "application/zip"],
|
|
88
|
+
["tar", "application/x-tar"],
|
|
89
|
+
["gz", "application/gzip"],
|
|
90
|
+
["tgz", "application/gzip"],
|
|
91
|
+
["rar", "application/vnd.rar"],
|
|
92
|
+
["7z", "application/x-7z-compressed"],
|
|
93
|
+
["bz2", "application/x-bzip2"],
|
|
94
|
+
["xz", "application/x-xz"],
|
|
95
|
+
// Fonts
|
|
96
|
+
["woff", "font/woff"],
|
|
97
|
+
["woff2", "font/woff2"],
|
|
98
|
+
["ttf", "font/ttf"],
|
|
99
|
+
["otf", "font/otf"],
|
|
100
|
+
["eot", "application/vnd.ms-fontobject"],
|
|
101
|
+
]);
|
|
102
|
+
export function mime(filePath) {
|
|
103
|
+
const ext = filePath.split(".").pop()?.toLowerCase();
|
|
104
|
+
if (!ext || ext === filePath.toLowerCase())
|
|
105
|
+
return "application/octet-stream";
|
|
106
|
+
return extensionToMime.get(ext) || "application/octet-stream";
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=mime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mime.js","sourceRoot":"","sources":["../../src/utils/mime.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC9B,OAAO;IACP,CAAC,KAAK,EAAE,2BAA2B,CAAC;IACpC,CAAC,MAAM,EAAE,2BAA2B,CAAC;IACrC,CAAC,KAAK,EAAE,yBAAyB,CAAC;IAClC,CAAC,KAAK,EAAE,0CAA0C,CAAC;IACnD,CAAC,IAAI,EAAE,8BAA8B,CAAC;IACtC,CAAC,MAAM,EAAE,0BAA0B,CAAC;IACpC,CAAC,KAAK,EAAE,0BAA0B,CAAC;IACnC,CAAC,KAAK,EAAE,yBAAyB,CAAC;IAClC,CAAC,IAAI,EAAE,gCAAgC,CAAC;IACxC,CAAC,KAAK,EAAE,gCAAgC,CAAC;IACzC,CAAC,KAAK,EAAE,gCAAgC,CAAC;IACzC,CAAC,MAAM,EAAE,iCAAiC,CAAC;IAC3C,CAAC,KAAK,EAAE,iCAAiC,CAAC;IAC1C,CAAC,KAAK,EAAE,gCAAgC,CAAC;IACzC,CAAC,MAAM,EAAE,0BAA0B,CAAC;IACpC,CAAC,KAAK,EAAE,0BAA0B,CAAC;IACnC,CAAC,KAAK,EAAE,eAAe,CAAC;IACxB,CAAC,KAAK,EAAE,qCAAqC,CAAC;IAE9C,SAAS;IACT,CAAC,KAAK,EAAE,WAAW,CAAC;IACpB,CAAC,KAAK,EAAE,YAAY,CAAC;IACrB,CAAC,MAAM,EAAE,YAAY,CAAC;IACtB,CAAC,KAAK,EAAE,WAAW,CAAC;IACpB,CAAC,MAAM,EAAE,YAAY,CAAC;IACtB,CAAC,MAAM,EAAE,YAAY,CAAC;IACtB,CAAC,KAAK,EAAE,cAAc,CAAC;IACvB,CAAC,KAAK,EAAE,WAAW,CAAC;I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AE,WAAW,EAAE,CAAC;IACrD,IAAI,CAAC,GAAG,IAAI,GAAG,KAAK,QAAQ,CAAC,WAAW,EAAE;QAAE,OAAO,0BAA0B,CAAC;IAC9E,OAAO,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,0BAA0B,CAAC;AAChE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kn-http-server",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/server.js",
|
|
6
|
+
"description": "A command-line http server",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"start": "node src/server.js",
|
|
9
|
+
"dev": "tsx watch src/server.ts",
|
|
10
|
+
"build": "tsc && node -e \"require('fs').cpSync('src/public', 'dist/public', {recursive:true})\"",
|
|
11
|
+
"preview": "node dist/server.js"
|
|
12
|
+
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"kn-http-server": "./dist/server.js"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"cli",
|
|
18
|
+
"http-server"
|
|
19
|
+
],
|
|
20
|
+
"author": "knkrn5",
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^25.0.9",
|
|
24
|
+
"tsx": "^4.21.0"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# kn-http-server
|
|
2
|
+
|
|
3
|
+
A lightweight, zero-dependency command-line HTTP server for serving static files and directories. It provides a simple interface for directory listings, file previews, and downloads.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Static File Serving:** Instantly serves files from the current directory.
|
|
8
|
+
- **Directory Listing:** Auto-generated HTML directory listings with intuitive navigation.
|
|
9
|
+
- **Preview & Download:** Built-in links to preview (👁️) or download (⬇️) files directly from the browser.
|
|
10
|
+
- **Customizable:** Configure port, binding address, and stream high-water mark via CLI flags.
|
|
11
|
+
- **Wide MIME Support:** Comprehensive support for text, images, audio, video, and application file types.
|
|
12
|
+
- **Zero Dependencies:** Built using only native Node.js modules.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
### Globally via npm
|
|
17
|
+
|
|
18
|
+
You can install the package globally to use it as a command-line tool anywhere on your system.
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install -g kn-http-server
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Run via npx
|
|
25
|
+
|
|
26
|
+
Alternatively, you can run it without installing using `npx`:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npx kn-http-server [options]
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
Navigate to the directory you want to serve and run:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
kn-http-server
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
By default, the server listens on `0.0.0.0:3000`.
|
|
41
|
+
|
|
42
|
+
### Command Line Options
|
|
43
|
+
|
|
44
|
+
You can customize the server behavior using the following flags:
|
|
45
|
+
|
|
46
|
+
| Flag | Description | Default | Example |
|
|
47
|
+
| :---- | :----------------------------------------------- | :---------- | :----------------------- |
|
|
48
|
+
| `-p` | **Port**: The port number to listen on. | `3000` | `kn-http-server -p 8080` |
|
|
49
|
+
| `-a` | **Address**: The IP address to bind to. | `0.0.0.0` | `kn-http-server -a 127.0.0.1` |
|
|
50
|
+
| `-hw` | **HighWaterMark**: Stream buffer size in bytes. | Node Default| `kn-http-server -hw 65536` |
|
|
51
|
+
|
|
52
|
+
### Examples
|
|
53
|
+
|
|
54
|
+
**Start on a specific port:**
|
|
55
|
+
```bash
|
|
56
|
+
kn-http-server -p 8080
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**Bind to localhost only:**
|
|
60
|
+
```bash
|
|
61
|
+
kn-http-server -a 127.0.0.1
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Set custom stream buffer size (HighWaterMark):**
|
|
65
|
+
```bash
|
|
66
|
+
kn-http-server -hw 64000
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Development
|
|
70
|
+
|
|
71
|
+
If you want to contribute or modify the server code:
|
|
72
|
+
|
|
73
|
+
1. **Clone the repository:**
|
|
74
|
+
```bash
|
|
75
|
+
git clone <repository-url>
|
|
76
|
+
cd http-server
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
2. **Start the server locally:**
|
|
80
|
+
```bash
|
|
81
|
+
node server.js
|
|
82
|
+
# OR with options
|
|
83
|
+
node server.js -p 4000
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
ISC
|
|
89
|
+
|