Skip to content

Commit e644db3

Browse files
committed
Updated Bun and Docs, minor improvements
1 parent d4565da commit e644db3

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,26 @@ Simple web server to serve static files from ONE assigned root-directory.
1818

1919
## Options
2020

21-
You can run `hyper-server --help` to view this table:
21+
You can run `hyper-server --help` to see the help wizard.
2222

2323
| Option | Default | Description
2424
| - | - | -
25-
| `--hot` | `false` | Enable hot-reloading.
25+
| `--hot` | `false` | Enable hot-reloading. Injects client-side script automatically.
2626
| `--root`, `-r` | `.` | Document root folder to serve
2727
| `--hostname`, `-h` | `localhost` | Server's hostname. When `0.0.0.0` serve both localhost and to local network.
2828
| `--port`, `-p` | `3000` | Port to listen to. Needs sudo to assign ports below 3000.
2929
30+
## Features/Todo
31+
32+
- [x] Hot-reloading (inject client script)
33+
- [ ] Server configuration file
34+
- [ ] SSL support
35+
- [ ] Service Workers
36+
- [ ] Production mode
37+
3038
## Resources
3139
3240
* `Bun.serve` - <https://bun.sh/docs/api/http>
3341
* `HTMLRewriter` - <https://developers.cloudflare.com/workers/runtime-apis/html-rewriter/>
42+
* `Commander.js` - <https://github.com/tj/commander.js>
43+

bin/hyper-server

-32.3 KB
Binary file not shown.

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
22
"name": "@hyper-hyper/hyper-server",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"description": "Simple web server to serve static content built powered by Bun.",
5-
"author": "Mikita Stankiewicz <[email protected]>",
5+
"author": {
6+
"name": "Mikita Stankiewicz",
7+
"email": "[email protected]",
8+
"url": "https://github.com/itsmikita"
9+
},
610
"private": "true",
711
"type": "module",
812
"main": "index.js",
@@ -11,11 +15,11 @@
1115
},
1216
"repository": {
1317
"type": "git",
14-
"url": "https://github.com/hyper-hyper/hyper-server-git"
18+
"url": "https://github.com/hyper-hyper/hyper-server.git"
1519
},
1620
"scripts": {
17-
"dev": "bun ./src/server.js --hot",
18-
"build": "bun build ./src/server.js --compile --outfile bin/hyper-server"
21+
"dev": "bun ./src/server.js --hot --hostname 127.0.0.1 --port 3000 --root ./src",
22+
"build": "bun build ./src/server.js --compile --minify --outfile bin/hyper-server"
1923
},
2024
"dependencies": {
2125
"bun": "^1.0.26",

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./server.js";

src/server.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const server = Bun.serve({
4949
const requestPath = new URL(request.url).pathname;
5050
console.log(`\n${request.method} ${requestPath}`);
5151
if(opts.hot && request.url.endsWith(HOT_CMD)) {
52-
console.log(`Server: Got '${HOT_CMD}' request, trying to upgrade...`);
52+
console.log(`Server: Got '${HOT_CMD}' request, upgrading...`);
5353
return server.upgrade(request);
5454
}
5555
let filePath = join(ROOT, requestPath);
@@ -75,7 +75,7 @@ export const server = Bun.serve({
7575
}
7676
);
7777
}
78-
return new Response(file, {headers:{"Content-Type": file.type}});
78+
return new Response(file, { headers: { "Content-Type": file.type } });
7979
},
8080
error: (error) => {
8181
if("ENOENT" === error.code) {
@@ -87,17 +87,17 @@ export const server = Bun.serve({
8787
port: PORT,
8888
websocket: {
8989
open: (ws) => {
90-
console.log(`WebSocket: Client connected. Subscribe to '${HOT_CMD}'`);
9190
ws.subscribe(HOT_CMD);
91+
console.log(`WebSocket: Client subscribed to '${HOT_CMD}'`);
9292
},
9393
message: (ws, message) => {
94-
console.log(`WebSocket: Client trying to communicate: `, ws, message);
94+
console.log(`WebSocket: Client trying to communicate: `, message);
9595
},
9696
close: (ws) => {
97-
console.log(`WebSocket: Client disconnected...`);
9897
ws.unsubscribe(HOT_CMD);
98+
console.log(`WebSocket: Client disconnected...`);
9999
}
100100
}
101101
});
102102

103-
console.log(`Started Web Server at: ${server.protocol}://${server.hostname}:${server.port}\n`);
103+
console.log(`\nStarted Web Server at: ${server.protocol}://${server.hostname}:${server.port}\n`);

0 commit comments

Comments
 (0)