@rubriclab/bunl 0.0.13 → 0.0.14
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/.env.example +3 -0
- package/client.ts +5 -2
- package/package.json +1 -1
- package/server.ts +4 -1
package/.env.example
ADDED
package/client.ts
CHANGED
|
@@ -21,14 +21,17 @@ async function main({
|
|
|
21
21
|
|
|
22
22
|
socket.addEventListener("message", async (event) => {
|
|
23
23
|
const data = JSON.parse(event.data as string);
|
|
24
|
-
console.log("message:", data);
|
|
25
24
|
|
|
26
|
-
if (
|
|
25
|
+
if (data.url) {
|
|
26
|
+
console.log(`\n\n↪ Your URL: \x1b[32m${data.url}\x1b[0m\n`);
|
|
27
|
+
if (open) browser(data.url);
|
|
28
|
+
}
|
|
27
29
|
|
|
28
30
|
if (data.method) {
|
|
29
31
|
const res = await fetch(`${url}${data.pathname}`, {
|
|
30
32
|
method: data.method,
|
|
31
33
|
headers: data.headers,
|
|
34
|
+
body: data.body,
|
|
32
35
|
});
|
|
33
36
|
|
|
34
37
|
const { status, statusText, headers } = res;
|
package/package.json
CHANGED
package/server.ts
CHANGED
|
@@ -34,8 +34,11 @@ serve<Client>({
|
|
|
34
34
|
// The magic: forward the req to the client
|
|
35
35
|
const client = clients.get(subdomain)!;
|
|
36
36
|
const { method, url, headers: reqHeaders } = req;
|
|
37
|
+
const reqBody = await req.text();
|
|
37
38
|
const { pathname } = new URL(url);
|
|
38
|
-
client.send(
|
|
39
|
+
client.send(
|
|
40
|
+
JSON.stringify({ method, pathname, body: reqBody, headers: reqHeaders })
|
|
41
|
+
);
|
|
39
42
|
|
|
40
43
|
// Wait for the client to cache its response above
|
|
41
44
|
await sleep(1);
|