bun-dev-server 0.0.3 → 0.0.5

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/index.ts CHANGED
@@ -49,8 +49,15 @@ export async function startBunDevServer(serverConfig: BunDevServerConfig) {
49
49
  development: true,
50
50
  tls: finalConfig.tls,
51
51
  async fetch(req, server) {
52
+ if(req.method === "OPTIONS") {
53
+ const response = new Response("", { status: 200 });
54
+ augumentHeaders(response);
55
+ return response;
56
+ }
52
57
  if (req.url.toLowerCase().endsWith("/favicon.ico")) {
53
- return new Response("", { status: 404 });
58
+ const response = new Response("", { status: 404 });
59
+ augumentHeaders(response);
60
+ return response;
54
61
  }
55
62
  if (req.url.toLowerCase().endsWith(finalConfig.websocketPath)) {
56
63
  if (server.upgrade(req)) {
@@ -75,7 +82,9 @@ export async function startBunDevServer(serverConfig: BunDevServerConfig) {
75
82
 
76
83
  if (!isDirectory) {
77
84
  const fl = Bun.file(dst + requestPath);
78
- return new Response(fl);
85
+ const response = new Response(fl);
86
+ augumentHeaders(response);
87
+ return response;
79
88
  }
80
89
  try {
81
90
  const allEntries = await readdir(dst + requestPath, {
@@ -98,9 +107,13 @@ export async function startBunDevServer(serverConfig: BunDevServerConfig) {
98
107
  };
99
108
  });
100
109
  const rnd = render(finalConfig.serveOutputEjs, { dirs, files });
101
- return new Response(rnd, { headers: { "Content-Type": "text/html" } });
110
+ const response = new Response(rnd, { headers: { "Content-Type": "text/html" } });
111
+ augumentHeaders(response);
112
+ return response;
102
113
  } catch {
103
- return new Response("Not Found", { status: 404 });
114
+ const response = new Response("Not Found", { status: 404 });
115
+ augumentHeaders(response);
116
+ return response;
104
117
  }
105
118
  },
106
119
 
@@ -168,6 +181,11 @@ export async function startBunDevServer(serverConfig: BunDevServerConfig) {
168
181
 
169
182
  }
170
183
 
184
+ function augumentHeaders(response: Response) {
185
+ response.headers.set("Access-Control-Allow-Origin", "*");
186
+ response.headers.set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
187
+ }
188
+
171
189
  async function cleanDirectory(dst: string) {
172
190
  const { stderr, exitCode } = await $`rm -rf ${dst}/*`.nothrow();
173
191
  if (exitCode !== 0) {
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "type": "git",
7
7
  "url": "https://github.com/SPWizard01/bun-dev-server"
8
8
  },
9
- "version": "0.0.3",
9
+ "version": "0.0.5",
10
10
  "module": "index.ts",
11
11
  "type": "module",
12
12
  "license": "MIT",
package/test/bun.lockb CHANGED
Binary file
package/test/bunrun.ts CHANGED
@@ -1,4 +1,3 @@
1
- // import { startBunDevServer } from "bun-dev-server";
2
1
  import { startBunDevServer } from "../index";
3
2
 
4
3
  startBunDevServer({
package/test/package.json CHANGED
@@ -3,8 +3,7 @@
3
3
  "module": "app.ts",
4
4
  "type": "module",
5
5
  "devDependencies": {
6
- "@types/bun": "^1.1.11",
7
- "bun-dev-server": "^0.0.2"
6
+ "@types/bun": "^1.1.11"
8
7
  },
9
8
  "peerDependencies": {
10
9
  "typescript": "^5.6.3"