@flash-tunnel/adapter-cloudflare 0.0.1 → 0.2.0

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.
Files changed (2) hide show
  1. package/dist/index.mjs +25 -5
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AdapterError } from '@flash-tunnel/types';
2
2
  import { spawnSync, spawn } from 'node:child_process';
3
3
  import process from 'node:process';
4
- import { sleep, stripAnsi } from '@flash-tunnel/utils';
4
+ import { sleep, shellInvocation, stripAnsi } from '@flash-tunnel/utils';
5
5
 
6
6
  function mapError(status, envelope) {
7
7
  const first = envelope.errors?.[0];
@@ -282,6 +282,23 @@ function createCloudflareDns(options) {
282
282
 
283
283
  const ADAPTER_ID = "cloudflare";
284
284
  const QUICK_URL_PATTERN = /https:\/\/[a-z0-9-]+\.trycloudflare\.com/;
285
+ function assertTunnelTarget(localUrl) {
286
+ let parsed;
287
+ try {
288
+ parsed = new URL(localUrl);
289
+ } catch {
290
+ throw new AdapterError(`Invalid tunnel target "${localUrl}"`, {
291
+ code: "INVALID_LOCAL_URL",
292
+ hint: "Pass a full http(s) URL such as http://127.0.0.1:5173"
293
+ });
294
+ }
295
+ if (parsed.pathname !== "/" || parsed.search) {
296
+ throw new AdapterError(`Tunnel target must be an origin without a path, got "${localUrl}"`, {
297
+ code: "INVALID_LOCAL_URL",
298
+ hint: "cloudflared keeps the incoming path, so only the origin can be proxied. Use http://host:port and put the path on the public URL instead"
299
+ });
300
+ }
301
+ }
285
302
  function createCloudflareTunnel(options = {}) {
286
303
  const cloudflaredPath = options.cloudflaredPath ?? "cloudflared";
287
304
  const api = options.apiToken ? new CloudflareApi({
@@ -313,9 +330,10 @@ function createCloudflareTunnel(options = {}) {
313
330
  return api;
314
331
  }
315
332
  function ensureCloudflared() {
316
- const check = spawnSync(cloudflaredPath, ["--version"], {
333
+ const invocation = shellInvocation(cloudflaredPath, ["--version"]);
334
+ const check = spawnSync(invocation.command, invocation.args, {
317
335
  encoding: "utf8",
318
- shell: process.platform === "win32",
336
+ shell: invocation.shell,
319
337
  timeout: 1e4,
320
338
  windowsHide: true
321
339
  });
@@ -392,6 +410,7 @@ function createCloudflareTunnel(options = {}) {
392
410
  },
393
411
  async provision(_ctx, spec) {
394
412
  reset();
413
+ assertTunnelTarget(spec.localUrl);
395
414
  if (plannedMode === "quick") {
396
415
  return {
397
416
  provider: ADAPTER_ID,
@@ -461,8 +480,9 @@ function createCloudflareTunnel(options = {}) {
461
480
  });
462
481
  }
463
482
  const args = named ? ["--no-autoupdate", "tunnel", "run"] : ["--no-autoupdate", "tunnel", "--url", localUrl];
464
- const child = spawn(cloudflaredPath, args, {
465
- shell: process.platform === "win32",
483
+ const invocation = shellInvocation(cloudflaredPath, args);
484
+ const child = spawn(invocation.command, invocation.args, {
485
+ shell: invocation.shell,
466
486
  stdio: ["ignore", "pipe", "pipe"],
467
487
  windowsHide: true,
468
488
  detached: process.platform !== "win32",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@flash-tunnel/adapter-cloudflare",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.2.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/flash-tunnel/flash-tunnel#readme",
7
7
  "repository": {
@@ -30,8 +30,8 @@
30
30
  "access": "public"
31
31
  },
32
32
  "dependencies": {
33
- "@flash-tunnel/types": "0.0.1",
34
- "@flash-tunnel/utils": "0.0.1"
33
+ "@flash-tunnel/types": "0.2.0",
34
+ "@flash-tunnel/utils": "0.2.0"
35
35
  },
36
36
  "scripts": {
37
37
  "stub": "unbuild --stub",