Skip to content

Commit e8f70bf

Browse files
committed
update usage
1 parent a9551a5 commit e8f70bf

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

index.mjs

+30-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
1-
import Server from 'bare-server-node';
2-
import http from 'http';
3-
import nodeStatic from 'node-static';
1+
import createBareServer from "@tomphttp/bare-server-node";
2+
import http from "node:http";
43

4+
const httpServer = http.createServer();
55

6-
const bare = new Server('/bare/', '');
7-
const serve = new nodeStatic.Server('static/');
6+
const bareServer = createBareServer("/", {
7+
logErrors: false,
8+
localAddress: undefined,
9+
maintainer: {
10+
11+
website: "https://github.com/tomphttp/",
12+
},
13+
});
814

9-
const server = http.createServer();
15+
httpServer.on("request", (req, res) => {
16+
if (bareServer.shouldRoute(req)) {
17+
bareServer.routeRequest(req, res);
18+
} else {
19+
res.writeHead(400);
20+
res.end("Not found.");
21+
}
22+
});
1023

11-
server.on('request', (request, response) => {
12-
if (bare.route_request(request, response)) return true;
13-
serve.serve(request, response);
24+
httpServer.on("upgrade", (req, socket, head) => {
25+
if (bareServer.shouldRoute(req)) {
26+
bareServer.routeUpgrade(req, socket, head);
27+
} else {
28+
socket.end();
29+
}
1430
});
1531

16-
server.on('upgrade', (req, socket, head) => {
17-
if(bare.route_upgrade(req, socket, head))return;
18-
socket.end();
32+
httpServer.on("listening", () => {
33+
console.log("HTTP server listening");
1934
});
2035

21-
server.listen(process.env.PORT || 6969);
36+
httpServer.listen({
37+
port: process.env.PORT || 6969,
38+
});

0 commit comments

Comments
 (0)