-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdev.js
More file actions
33 lines (29 loc) · 862 Bytes
/
Copy pathdev.js
File metadata and controls
33 lines (29 loc) · 862 Bytes
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
import index from "./public/index.html";
const API_TARGET = "https://your-cors-sensitive-api.io/api";
// Proxy to dodge CORS hassle from localhost (remove or tweak to your liking)
async function proxyApi(req) {
const url = new URL(req.url);
const path = url.pathname.replace(/^\/api/, "") + url.search;
const headers = new Headers(req.headers);
headers.delete("host");
console.log("[api-forward req] →", req.method, path);
const res = await fetch(API_TARGET + path, {
method: req.method,
headers,
body: req.body,
redirect: "manual",
});
console.log("[api-forward res] ←", res.status, path);
return res;
}
const server = Bun.serve({
port: 1337,
development: {
hmr: false, // handled by elm-watch
},
routes: {
"/api/*": proxyApi,
"/*": index,
},
});
console.log(`dev server running: ${server.url}`);