@dnax/serve 0.0.0-stage → 0.0.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/README.md CHANGED
@@ -1,3 +1,82 @@
1
- # Temporary Holding Version
1
+ # @dnax/serve
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A zero-config static file server for [Bun](https://bun.com), with the same CLI
4
+ syntax as [`http-server`](https://github.com/http-party/http-server).
5
+
6
+ The package is published as `@dnax/serve` and installs the `dnx` command.
7
+
8
+ ## Usage
9
+
10
+ ```bash
11
+ bun run src/cli.ts serve [path] [options]
12
+ ```
13
+
14
+ Or install it globally and use the `dnx` binary:
15
+
16
+ ```bash
17
+ bun add -g @dnax/serve # or: npm install -g @dnax/serve
18
+ dnx serve ./public -p 8080
19
+ ```
20
+
21
+ For local development, link the package instead:
22
+
23
+ ```bash
24
+ bun link # from this directory
25
+ dnx serve ./public -p 8080
26
+ ```
27
+
28
+ `[path]` defaults to `./public` when that directory exists, otherwise `./`.
29
+ The `serve` subcommand is optional, so `dnx [path] [options]` also works.
30
+
31
+ ```bash
32
+ dnx serve ./dist -p 3000 -c-1 # no caching
33
+ dnx serve . -p 0 # first free port starting at 8080
34
+ dnx serve . --cors -g -b # CORS + precompressed .gz/.br
35
+ dnx serve . --username admin --password secret
36
+ dnx serve . -S -C cert.pem -K key.pem # HTTPS
37
+ dnx serve . -P http://localhost:3001 # proxy unresolved requests
38
+ ```
39
+
40
+ Run `dnx serve --help` for the full option list. Flags mirror `http-server`,
41
+ including `-p/-a/-d/-i/-g/-b/-e/-s/-o/-c/-t/-U/-T/-P/-S/-C/-K/-r/-H`,
42
+ `--cors[=headers]`, `--coop`, `--private-network-access`, `--log-ip`,
43
+ `--no-dotfiles`, `--hide-permissions`, `--mimetypes`, `--allowed-hosts`,
44
+ `--base-dir`, `--dir-overrides-404` and `--proxy-all`.
45
+
46
+ Magic files work as in `http-server`: `index.<ext>` is served for directories
47
+ and `404.<ext>` is served for missing files.
48
+
49
+ ## Library
50
+
51
+ ```ts
52
+ import { startStaticServer } from "@dnax/serve";
53
+
54
+ const server = await startStaticServer({
55
+ root: "./public",
56
+ port: 3000,
57
+ cors: true,
58
+ gzip: true,
59
+ });
60
+
61
+ console.log(server.url);
62
+ // server.stop();
63
+ ```
64
+
65
+ `resolveOptions()` and `createRequestHandler()` are exported for use with your
66
+ own `Bun.serve({ fetch })` configuration.
67
+
68
+ ## Publishing
69
+
70
+ Scoped packages are private by default, so publish with public access:
71
+
72
+ ```bash
73
+ npm publish --access public
74
+ ```
75
+
76
+ ## Development
77
+
78
+ ```bash
79
+ bun install
80
+ bun run typecheck
81
+ bun run start
82
+ ```
package/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ export {
2
+ createRequestHandler,
3
+ resolveOptions,
4
+ startStaticServer,
5
+ type ResolvedServeOptions,
6
+ type ServeOptions,
7
+ type StaticServer,
8
+ } from "./src/server.ts";
package/package.json CHANGED
@@ -1,6 +1,27 @@
1
1
  {
2
2
  "name": "@dnax/serve",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1",
4
+ "module": "index.ts",
5
+ "type": "module",
6
+ "private": false,
7
+ "bin": {
8
+ "dnx": "src/cli.ts"
9
+ },
10
+ "exports": {
11
+ ".": "./index.ts"
12
+ },
13
+ "files": [
14
+ "index.ts",
15
+ "src"
16
+ ],
17
+ "scripts": {
18
+ "start": "bun run src/cli.ts serve",
19
+ "typecheck": "bun check"
20
+ },
21
+ "devDependencies": {
22
+ "@types/bun": "latest"
23
+ },
24
+ "peerDependencies": {
25
+ "typescript": "^7"
26
+ }
27
+ }