http-server-rs 0.0.7 → 0.0.20

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,39 +8,69 @@ https://github.com/user-attachments/assets/7b6bbee0-3428-4c9f-80a6-2804ddac6e01
8
8
 
9
9
  ## Installation
10
10
 
11
+ ### Cargo
12
+
13
+ ```bash
14
+ # Installs globally
15
+ cargo install http-server-rs
16
+ ```
17
+
11
18
  ### NPM
12
19
 
13
20
  ```bash
14
- # Rerun to update
15
- npm install -g http-server-rs
21
+ # Installs to ./node_modules
22
+ npm install http-server-rs
23
+ npx http-server-rs --help
24
+ ```
25
+
26
+ If you want to override the binary used (for custom platforms)
27
+ ```bash
28
+ npm install http-server-rs
29
+
30
+ export HTTP_SERVER_RS_BIN_OVERRIDE=/path/to/http-server-rs
31
+ npx http-server-rs --help # Uses the override
16
32
  ```
17
33
 
18
- ### Binary Install Script
34
+ ### Manual Install
35
+
36
+ Download the latest binary from [GitHub Releases](https://github.com/alshdavid-public/http-server-rs/releases/latest) and add it to your `PATH`
19
37
 
20
38
  ```bash
21
- # Rerun to update
22
- eval $(curl -sSf https://raw.githubusercontent.com/alshdavid/http-server-rs/refs/heads/main/install.sh | sh)
39
+ # Linux AMD64 (Change for your platform)
40
+ curl -L --url https://github.com/alshdavid/http-server-rs/releases/latest/download/http-server-linux-amd64.tar.gz | tar -xvzf - -C $HOME/.local/bin
41
+
42
+ # Add to PATH if not already there:
43
+ echo "\nexport \PATH=\$PATH:\$HOME/.local/bin\n" >> $HOME/.zshrc
44
+ echo "\nexport \PATH=\$PATH:\$HOME/.local/bin\n" >> $HOME/.bashrc
23
45
  ```
24
46
 
25
- ## Usage
47
+ ## Example Usage
26
48
 
27
49
  ```bash
28
50
  # Use default configuration
29
- http-server
51
+ http-server-rs
52
+
53
+ # Enable CORS, reroute requests to index.html and automatically compress served files
54
+ http-server-rs --cors --spa -Z ./public
30
55
 
31
- # Arguments
32
- # Enable CORS, reroute requests to index.html and automatically compress to brotli
33
- http-server --cors --spa -Z ./public
56
+ # Responds with headers required for SharedArrayBuffer
57
+ http-server-rs --shared-array-buffer ./public
58
+
59
+ # Automatically transpiles TypeScript to JavaScript on request
60
+ http-server-rs --transpile ./public
61
+
62
+ # Proxy /api to an external backend (quotes are required)
63
+ http-server-rs --proxy "path=/api&target=http://localhost:3000" ./public
34
64
 
35
65
  # Custom Headers
36
- http-server -H X-Custom-Header:some-value
66
+ http-server-rs -H X-Custom-Header:some-value
37
67
  ```
38
68
 
39
69
  ```
40
- Usage: http-server [OPTIONS] [SERVE_DIR]
70
+ Usage: http-server-rs [OPTIONS] [SERVE_DIR]
41
71
 
42
72
  Arguments:
43
- [SERVE_DIR] Target directory to serve [default: ./dist]
73
+ [SERVE_DIR] Target directory to serve [default: ./]
44
74
 
45
75
  Options:
46
76
  -a, --address <ADDRESS>
@@ -63,6 +93,8 @@ Options:
63
93
  Enable headers for SharedArrayBuffer
64
94
  -Q, --quiet
65
95
  Don't print any logs to terminal
96
+ -t, --transpile
97
+ Transpile served files
66
98
  -w, --watch
67
99
  Watch folder for changes and trigger a browser reload
68
100
  --watch-dir <WATCH_DIR>
@@ -71,10 +103,24 @@ Options:
71
103
  Don't automatically inject watch listener into html
72
104
  --stream-buffer-size <STREAM_BUFFER_SIZE>
73
105
  Configure the buffer size when streaming files [default: 4000]
106
+ --proxy <PROXY>
107
+ Reverse proxy routes (URL-encoded, e.g. "path=/api&target=http://localhost:3000")
74
108
  -h, --help
75
109
  Print help
76
110
  ```
77
111
 
112
+ ## Live Transpile TypeScript
113
+
114
+ Will live transpile TypeScript to JavaScript on request. This allows serving TypeScript sources
115
+ directly to the browser without a build step.
116
+
117
+ ```bash
118
+ http-server-rs --transpile --port 8080 ./testing/transpile/react
119
+
120
+ # Returns transpiled JavaScript that runs directly in the browser
121
+ curl http://localhost:8080/app.tsx
122
+ ```
123
+
78
124
  ## Watch Mode
79
125
 
80
126
  `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.20",
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