-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (28 loc) · 798 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import path from "path";
const PORT = 6969;
const PATH_TO_WEB_APP_WITH_TRAILING_SLASH = "./web-app/";
Bun.serve({
port: PORT,
fetch(req) {
const url = new URL(req.url);
if (url.pathname === "/")
return new Response(
Bun.file(PATH_TO_WEB_APP_WITH_TRAILING_SLASH + "index.html")
);
if (
url.pathname &&
Bun.file(
PATH_TO_WEB_APP_WITH_TRAILING_SLASH + path.normalize(url.pathname)
).size > 0
) {
return new Response(
Bun.file(
PATH_TO_WEB_APP_WITH_TRAILING_SLASH + path.normalize(url.pathname)
)
);
}
return new Response("404, file not found");
},
});
console.log("your react app is running on port " + PORT);
console.log("do not use this web server in a production environment");