wtt-connect 0.2.49 → 0.2.50
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/package.json +1 -1
- package/src/main.js +14 -0
package/package.json
CHANGED
package/src/main.js
CHANGED
|
@@ -149,6 +149,7 @@ async function previewPort(config, argv) {
|
|
|
149
149
|
if (!Number.isInteger(port) || port < 1024 || port > 65535 || port === 3000) {
|
|
150
150
|
throw new Error('preview-port requires --port <1024-65535>, excluding 3000');
|
|
151
151
|
}
|
|
152
|
+
await assertLocalPreviewPort(port, Number(argv.portCheckTimeout || argv.timeout || 5000));
|
|
152
153
|
const keepLast = previewKeepLast(config, argv);
|
|
153
154
|
const cleanup = cleanupOldPreviews(config, {
|
|
154
155
|
currentPort: port,
|
|
@@ -195,6 +196,19 @@ async function previewPort(config, argv) {
|
|
|
195
196
|
console.log(JSON.stringify({ ok: true, port, url, preview_url: url, snapshot, markdown, cleanup, published }, null, 2));
|
|
196
197
|
}
|
|
197
198
|
|
|
199
|
+
async function assertLocalPreviewPort(port, timeoutMs = 5000) {
|
|
200
|
+
const url = `http://127.0.0.1:${port}/`;
|
|
201
|
+
try {
|
|
202
|
+
await fetch(url, {
|
|
203
|
+
method: 'GET',
|
|
204
|
+
signal: AbortSignal.timeout(Math.max(1000, Math.min(Number(timeoutMs || 5000), 15000))),
|
|
205
|
+
});
|
|
206
|
+
} catch (error) {
|
|
207
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
208
|
+
throw new Error(`preview-port local server is not reachable at ${url}: ${message}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
198
212
|
async function createPreviewSnapshot(config, argv, { title = 'Cloud Sandbox Preview' } = {}) {
|
|
199
213
|
const dir = String(argv.snapshotDir || '').trim();
|
|
200
214
|
if (!dir) return null;
|