http-server-rs 0.0.7 → 0.0.19

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/README.md CHANGED
@@ -8,11 +8,11 @@ https://github.com/user-attachments/assets/7b6bbee0-3428-4c9f-80a6-2804ddac6e01
8
8
 
9
9
  ## Installation
10
10
 
11
- ### NPM
11
+ ### Cargo
12
12
 
13
13
  ```bash
14
14
  # Rerun to update
15
- npm install -g http-server-rs
15
+ cargo install http-server-rs
16
16
  ```
17
17
 
18
18
  ### Binary Install Script
@@ -37,7 +37,7 @@ http-server -H X-Custom-Header:some-value
37
37
  ```
38
38
 
39
39
  ```
40
- Usage: http-server [OPTIONS] [SERVE_DIR]
40
+ Usage: http-server-rs [OPTIONS] [SERVE_DIR]
41
41
 
42
42
  Arguments:
43
43
  [SERVE_DIR] Target directory to serve [default: ./dist]
@@ -63,6 +63,8 @@ Options:
63
63
  Enable headers for SharedArrayBuffer
64
64
  -Q, --quiet
65
65
  Don't print any logs to terminal
66
+ -t, --transpile
67
+ Transpile served files
66
68
  -w, --watch
67
69
  Watch folder for changes and trigger a browser reload
68
70
  --watch-dir <WATCH_DIR>
@@ -71,10 +73,24 @@ Options:
71
73
  Don't automatically inject watch listener into html
72
74
  --stream-buffer-size <STREAM_BUFFER_SIZE>
73
75
  Configure the buffer size when streaming files [default: 4000]
76
+ --proxy <PROXY>
77
+ Reverse proxy routes (URL-encoded, e.g. "path=/api&target=http://localhost:3000")
74
78
  -h, --help
75
79
  Print help
76
80
  ```
77
81
 
82
+ ## Live Transpile TypeScript
83
+
84
+ Will live transpile TypeScript to JavaScript on request. This allows serving TypeScript sources
85
+ directly to the browser without a build step.
86
+
87
+ ```bash
88
+ http-server-rs --transpile --port 8080 ./testing/transpile/react
89
+
90
+ # Returns transpiled JavaScript that runs directly in the browser
91
+ curl http://localhost:8080/app.tsx
92
+ ```
93
+
78
94
  ## Watch Mode
79
95
 
80
96
  `http-server` under `--watch` mode can watch the served directory for changes and emit an event to the client notifying of a change. By default the server will intercept html files and inject a JavaScript script which subscribes to change events and triggers a page reload.
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env node
2
+
3
+ import * as child_process from "node:child_process";
4
+ import * as fs from "node:fs";
5
+ import * as path from "node:path";
6
+ import * as process from "node:process";
7
+ import * as url from "node:url";
8
+
9
+ const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
10
+
11
+ const SUPPORTED = [
12
+ "linux-x64",
13
+ "linux-arm64",
14
+ "darwin-arm64",
15
+ "win32-x64",
16
+ "win32-arm64",
17
+ ];
18
+
19
+ const TARGET = `${process.platform}-${process.arch}`;
20
+ const EXTENSION = process.platform === "win32" ? ".exe" : "";
21
+
22
+ const override = process.env.HTTP_SERVER_RS_BIN_OVERRIDE;
23
+
24
+ let binary;
25
+
26
+ if (override) {
27
+ if (!fs.existsSync(override)) {
28
+ console.error(
29
+ `http-server-rs: HTTP_SERVER_RS_BIN_OVERRIDE is set, but no file exists at:\n` +
30
+ ` ${override}\n\n` +
31
+ `Unset it to use the bundled binary for ${TARGET}.`,
32
+ );
33
+ process.exit(1);
34
+ }
35
+ binary = override;
36
+ } else {
37
+ binary = path.join(__dirname, `http-server-rs-${TARGET}${EXTENSION}`);
38
+
39
+ if (!fs.existsSync(binary)) {
40
+ console.error(
41
+ `http-server-rs: no bundled binary for ${TARGET}.\n\n` +
42
+ `Expected it at:\n` +
43
+ ` ${binary}\n\n` +
44
+ `Supported platforms: ${SUPPORTED.join(", ")}\n` +
45
+ `Set HTTP_SERVER_RS_BIN_OVERRIDE to run a binary from an explicit path.\n` +
46
+ `https://github.com/alshdavid/http-server-rs`,
47
+ );
48
+ process.exit(1);
49
+ }
50
+ }
51
+
52
+ const result = child_process.spawnSync(binary, process.argv.slice(2), {
53
+ stdio: "inherit",
54
+ windowsHide: true,
55
+ });
56
+
57
+ if (result.error) {
58
+ console.error(`http-server-rs: failed to execute ${binary}`);
59
+ console.error(result.error.message);
60
+ process.exit(1);
61
+ }
62
+
63
+ if (result.signal) {
64
+ process.kill(process.pid, result.signal);
65
+ }
66
+
67
+ process.exit(result.status ?? 1);
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "http-server-rs",
3
- "version": "0.0.7",
3
+ "version": "0.0.19",
4
+ "license": "MIT",
5
+ "type": "module",
4
6
  "bin": {
5
- "http-server-rs": "./http-server.exe"
7
+ "http-server-rs": "http-server-rs.js"
6
8
  },
7
- "scripts": {
8
- "postinstall": "node ./postinstall.mjs"
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/alshdavid/http-server-rs.git"
9
12
  }
10
13
  }
package/http-server.exe DELETED
@@ -1,11 +0,0 @@
1
- This is a placeholder file required because npm will only create
2
- a symlink to a `package.json#bin` entry if the file exists.
3
-
4
- This file is replaced in a postinstall step with the actual binary
5
- downloaded from GitHub releases.
6
-
7
- This file has an .exe extension for Windows compatibility because
8
- Windows requires a file extension to know a file is executable.
9
-
10
- Linux and MacOS will be able to run the file as a normal binary
11
- regardless of the extension being present.
package/postinstall.mjs DELETED
@@ -1,91 +0,0 @@
1
- import * as process from "node:process";
2
- import * as fs from "node:fs";
3
- import * as path from "node:path";
4
- import * as url from "node:url";
5
- import * as stream from "node:stream";
6
- import * as tar from "./tar.cjs";
7
-
8
- const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
9
- const __bin = path.join(__dirname, "http-server.exe");
10
- const __bin_unix = path.join(__dirname, "http-server");
11
-
12
- const HTTP_SERVER_RS_BIN_PATH = process.env.HTTP_SERVER_RS_BIN_PATH;
13
- const HTTP_SERVER_RS_SKIP_DOWNLOAD = process.env.HTTP_SERVER_RS_SKIP_DOWNLOAD;
14
- const HTTP_SERVER_RS_FORCE_TAG = process.env.HTTP_SERVER_RS_FORCE_TAG;
15
-
16
- const os = {
17
- darwin: "macos",
18
- linux: "linux",
19
- win32: "windows",
20
- }[process.platform];
21
-
22
- const arch = {
23
- arm64: "arm64",
24
- x64: "amd64",
25
- }[process.arch];
26
-
27
- void (async function main() {
28
- if (HTTP_SERVER_RS_SKIP_DOWNLOAD === "true") {
29
- // Do nothing
30
- } else if (
31
- HTTP_SERVER_RS_BIN_PATH &&
32
- fs.existsSync(HTTP_SERVER_RS_BIN_PATH)
33
- ) {
34
- await fs.promises.rm(__bin, { recursive: true, force: true });
35
- await fs.promises.symlink(__bin, HTTP_SERVER_RS_BIN_PATH);
36
- } else {
37
- await downloadBin();
38
- }
39
- })();
40
-
41
- async function downloadBin() {
42
- if (!arch || !os) {
43
- throw new Error(
44
- "Unable to determine what Atlaspack Version Manager binary to download"
45
- );
46
- }
47
-
48
- let tag = HTTP_SERVER_RS_FORCE_TAG || "latest";
49
- if (fs.existsSync(path.join(__dirname, "tag"))) {
50
- tag = (
51
- await fs.promises.readFile(path.join(__dirname, "tag"), "utf8")
52
- ).trim();
53
- }
54
-
55
- let url = `https://github.com/alshdavid/http-server-rs/releases/latest/download/http-server-${os}-${arch}.tar.gz`;
56
- if (tag !== "latest") {
57
- url = `https://github.com/alshdavid/http-server-rs/releases/download/${tag}/http-server-${os}-${arch}.tar.gz`;
58
- }
59
-
60
- const response = await globalThis.fetch(url);
61
- if (!response.ok) {
62
- throw new Error("Unable to fetch http-server-rs binary");
63
- }
64
-
65
- const body = await response.bytes();
66
- const file = new stream.Duplex();
67
-
68
- file.push(body);
69
- file.push(null);
70
-
71
- if (fs.existsSync(__bin)) {
72
- fs.rmSync(__bin, { recursive: true, force: true });
73
- }
74
-
75
- let writable = tar.x({
76
- C: __dirname,
77
- chmod: true,
78
- });
79
-
80
- file.pipe(writable);
81
- await new Promise((res) => writable.on("close", res));
82
-
83
- if (fs.existsSync(__bin)) {
84
- await fs.promises.rm(__bin, { recursive: true, force: true });
85
- }
86
-
87
- if (fs.existsSync(__bin_unix)) {
88
- await fs.promises.rename(__bin_unix, __bin);
89
- await fs.promises.chmod(__bin, "755");
90
- }
91
- }
package/tag DELETED
@@ -1 +0,0 @@
1
- v2025.10.10.0631.a4fb