@lasso-ai/cli 1.0.4 → 1.0.6
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.
|
@@ -25,6 +25,30 @@ function freePort() {
|
|
|
25
25
|
});
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
+
function waitForNext(nextPort, timeoutMs = 60_000) {
|
|
29
|
+
const deadline = Date.now() + timeoutMs;
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
const check = () => {
|
|
32
|
+
const request = node_http_1.default.get({
|
|
33
|
+
hostname: "127.0.0.1",
|
|
34
|
+
port: nextPort,
|
|
35
|
+
path: "/",
|
|
36
|
+
headers: { connection: "close" },
|
|
37
|
+
}, (response) => {
|
|
38
|
+
response.resume();
|
|
39
|
+
response.once("end", resolve);
|
|
40
|
+
});
|
|
41
|
+
request.once("error", () => {
|
|
42
|
+
if (Date.now() >= deadline) {
|
|
43
|
+
reject(new Error(`Next.js did not become ready on port ${nextPort} within ${timeoutMs / 1000}s.`));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
setTimeout(check, 250);
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
check();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
28
52
|
void (async () => {
|
|
29
53
|
const nextPort = await freePort();
|
|
30
54
|
const nextBin = node_path_1.default.join(cwd, "node_modules", ".bin", "next");
|
|
@@ -46,6 +70,7 @@ void (async () => {
|
|
|
46
70
|
const contentType = String(proxyRes.headers["content-type"] || "");
|
|
47
71
|
const headers = { ...proxyRes.headers };
|
|
48
72
|
delete headers["content-length"];
|
|
73
|
+
delete headers["content-encoding"];
|
|
49
74
|
res.writeHead(proxyRes.statusCode || 200, headers);
|
|
50
75
|
res.end(contentType.includes("text/html")
|
|
51
76
|
? body.replace("</head>", `<script src="/__lasso/overlay.js?bridgePort=${bridgePort}"></script></head>`)
|
|
@@ -58,7 +83,7 @@ void (async () => {
|
|
|
58
83
|
res.end(node_fs_1.default.readFileSync(bundlePath, "utf8"));
|
|
59
84
|
return;
|
|
60
85
|
}
|
|
61
|
-
proxy.web(req, res, {}, (error) => {
|
|
86
|
+
proxy.web(req, res, { headers: { "accept-encoding": "identity" } }, (error) => {
|
|
62
87
|
if (!res.headersSent) {
|
|
63
88
|
res.writeHead(502, { "content-type": "text/plain" });
|
|
64
89
|
res.end(`Next.js is still starting: ${error.message}`);
|
|
@@ -66,6 +91,14 @@ void (async () => {
|
|
|
66
91
|
});
|
|
67
92
|
});
|
|
68
93
|
server.on("upgrade", (req, socket, head) => proxy.ws(req, socket, head));
|
|
94
|
+
try {
|
|
95
|
+
await waitForNext(nextPort);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
bridge.close();
|
|
99
|
+
nextProcess.kill("SIGTERM");
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
69
102
|
server.listen(publicPort, "127.0.0.1");
|
|
70
103
|
const shutdown = () => {
|
|
71
104
|
bridge.close();
|
package/dist/cli/server/next.js
CHANGED
|
@@ -39,7 +39,10 @@ async function startNextServer(cwd) {
|
|
|
39
39
|
proxyRes.on("end", () => {
|
|
40
40
|
const body = Buffer.concat(chunks).toString("utf-8");
|
|
41
41
|
const contentType = proxyRes.headers["content-type"] || "";
|
|
42
|
-
|
|
42
|
+
const headers = { ...proxyRes.headers };
|
|
43
|
+
delete headers["content-length"];
|
|
44
|
+
delete headers["content-encoding"];
|
|
45
|
+
res.writeHead(proxyRes.statusCode || 200, headers);
|
|
43
46
|
if (contentType.includes("text/html")) {
|
|
44
47
|
res.end(body.replace("</head>", `<script src="/__lasso/overlay.js?bridgePort=3056"></script></head>`));
|
|
45
48
|
}
|
|
@@ -55,7 +58,7 @@ async function startNextServer(cwd) {
|
|
|
55
58
|
serveOverlayBundle(res);
|
|
56
59
|
return;
|
|
57
60
|
}
|
|
58
|
-
proxy.web(req, res, {}, (err) => {
|
|
61
|
+
proxy.web(req, res, { headers: { "accept-encoding": "identity" } }, (err) => {
|
|
59
62
|
console.error(chalk_1.default.red("Proxy error:"), err.message);
|
|
60
63
|
res.writeHead(502);
|
|
61
64
|
res.end("Bad gateway — is the Next.js dev server still starting up?");
|
package/package.json
CHANGED