which-url 0.0.5 → 0.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.
package/README.md CHANGED
@@ -148,6 +148,18 @@ Framework-prefixed env vars like `NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL` are
148
148
 
149
149
  ## Advanced
150
150
 
151
+ ### Portless
152
+
153
+ Zero config — [portless](https://portless.sh) sets `PORTLESS_URL` and `which-url` picks it up automatically.
154
+
155
+ ```json
156
+ "dev": "portless run next dev"
157
+ ```
158
+
159
+ ```
160
+ origin → https://myapp.localhost
161
+ ```
162
+
151
163
  ### Tunnels (ngrok, Cloudflare Tunnel)
152
164
 
153
165
  Tunnel URLs can't be auto-detected — they're external to the app process. Set `APP_URL`:
package/dist/env.d.ts CHANGED
@@ -1,3 +1,7 @@
1
1
  import type { AppEnv } from "./types";
2
- export declare function resolveEnv(): AppEnv;
2
+ export interface EnvResult {
3
+ env: AppEnv;
4
+ debugLabel: string;
5
+ }
6
+ export declare function resolveEnv(): EnvResult;
3
7
  //# sourceMappingURL=env.d.ts.map
package/dist/env.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC,wBAAgB,UAAU,IAAI,MAAM,CAwBnC"}
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAA;IACX,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,UAAU,IAAI,SAAS,CAyBtC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { WhichUrl, AppEnv, Platform, Source } from "./types";
1
+ import type { WhichUrl, AppEnv, Platform } from "./types";
2
2
  declare let _resolved: WhichUrl;
3
3
  export declare const href: string;
4
4
  export declare const origin: string;
@@ -8,11 +8,9 @@ export declare const protocol: string;
8
8
  export declare const port: string;
9
9
  export declare const env: AppEnv;
10
10
  export declare const platform: Platform;
11
- export declare const source: Source;
12
- export declare const debug: string;
13
11
  export declare const isProduction: boolean;
14
12
  export declare const isPreview: boolean;
15
13
  export declare const isLocal: boolean;
16
14
  export default _resolved;
17
- export type { WhichUrl, AppEnv, Platform, Source };
15
+ export type { WhichUrl, AppEnv, Platform };
18
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AA0BjE,QAAA,IAAI,SAAS,EAAE,QAAQ,CAAA;AAyBvB,eAAO,MAAM,IAAI,EAAE,MAAuB,CAAA;AAC1C,eAAO,MAAM,MAAM,EAAE,MAAyB,CAAA;AAC9C,eAAO,MAAM,QAAQ,EAAE,MAA2B,CAAA;AAClD,eAAO,MAAM,IAAI,EAAE,MAAuB,CAAA;AAC1C,eAAO,MAAM,QAAQ,EAAE,MAA2B,CAAA;AAClD,eAAO,MAAM,IAAI,EAAE,MAAuB,CAAA;AAC1C,eAAO,MAAM,GAAG,EAAE,MAAsB,CAAA;AACxC,eAAO,MAAM,QAAQ,EAAE,QAA6B,CAAA;AACpD,eAAO,MAAM,MAAM,EAAE,MAAyB,CAAA;AAC9C,eAAO,MAAM,KAAK,EAAE,MAAwB,CAAA;AAC5C,eAAO,MAAM,YAAY,EAAE,OAAgC,CAAA;AAC3D,eAAO,MAAM,SAAS,EAAE,OAA6B,CAAA;AACrD,eAAO,MAAM,OAAO,EAAE,OAA2B,CAAA;AAGjD,eAAe,SAAS,CAAA;AAExB,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAqCzD,QAAA,IAAI,SAAS,EAAE,QAAQ,CAAA;AA8BvB,eAAO,MAAM,IAAI,EAAE,MAAuB,CAAA;AAC1C,eAAO,MAAM,MAAM,EAAE,MAAyB,CAAA;AAC9C,eAAO,MAAM,QAAQ,EAAE,MAA2B,CAAA;AAClD,eAAO,MAAM,IAAI,EAAE,MAAuB,CAAA;AAC1C,eAAO,MAAM,QAAQ,EAAE,MAA2B,CAAA;AAClD,eAAO,MAAM,IAAI,EAAE,MAAuB,CAAA;AAC1C,eAAO,MAAM,GAAG,EAAE,MAAsB,CAAA;AACxC,eAAO,MAAM,QAAQ,EAAE,QAA6B,CAAA;AACpD,eAAO,MAAM,YAAY,EAAE,OAAgC,CAAA;AAC3D,eAAO,MAAM,SAAS,EAAE,OAA6B,CAAA;AACrD,eAAO,MAAM,OAAO,EAAE,OAA2B,CAAA;AAGjD,eAAe,SAAS,CAAA;AAExB,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAA"}
package/dist/index.js CHANGED
@@ -148,21 +148,23 @@ function resolveUrl() {
148
148
  const env = getEnv();
149
149
  const override = getVar(env, "APP_URL");
150
150
  if (override)
151
- return { url: normalizeUrl(override), source: "override" };
151
+ return { url: normalizeUrl(override), debugLabel: `[override] APP_URL=${override}` };
152
+ if (env.PORTLESS_URL)
153
+ return { url: env.PORTLESS_URL, debugLabel: `[portless] PORTLESS_URL=${env.PORTLESS_URL}` };
152
154
  for (const p of providers) {
153
155
  if (p.detect(env)) {
154
156
  const url = p.resolveUrl(env);
155
157
  if (url)
156
- return { url: normalizeUrl(url), source: "provider" };
158
+ return { url: normalizeUrl(url), debugLabel: `[provider:${p.name}] url=${url}` };
157
159
  }
158
160
  }
159
161
  if (typeof window !== "undefined" && window.location) {
160
- return { url: window.location.origin, source: "browser" };
162
+ return { url: window.location.origin, debugLabel: `[browser] window.location.origin` };
161
163
  }
162
164
  const isProduction = env.NODE_ENV === "production";
163
165
  if (!isProduction) {
164
166
  const port = env.PORT || "3000";
165
- return { url: `http://localhost:${port}`, source: "fallback" };
167
+ return { url: `http://localhost:${port}`, debugLabel: `[fallback] PORT=${port}` };
166
168
  }
167
169
  throw new Error("which-url: Cannot detect app URL. Set APP_URL environment variable.");
168
170
  }
@@ -182,28 +184,29 @@ function resolveEnv() {
182
184
  const env = getEnv();
183
185
  const appEnv = getVar(env, "APP_ENV");
184
186
  if (appEnv && validEnvs.includes(appEnv)) {
185
- return appEnv;
187
+ return { env: appEnv, debugLabel: `APP_ENV=${appEnv}` };
186
188
  }
187
189
  if (env.NODE_ENV === "development")
188
- return "local";
190
+ return { env: "local", debugLabel: "NODE_ENV=development" };
189
191
  for (const p of providers) {
190
192
  if (p.detect(env)) {
191
- return p.resolveEnv(env);
193
+ const resolved = p.resolveEnv(env);
194
+ return { env: resolved, debugLabel: `${p.name}:${resolved}` };
192
195
  }
193
196
  }
194
197
  if (env.NODE_ENV === "production")
195
- return "production";
196
- return "local";
198
+ return { env: "production", debugLabel: "NODE_ENV=production" };
199
+ return { env: "local", debugLabel: "default" };
197
200
  }
198
201
 
199
202
  // src/index.ts
200
203
  function resolve() {
201
- const { url, source } = resolveUrl();
204
+ const { url, debugLabel: urlDebug } = resolveUrl();
202
205
  const parsed = new URL(url);
203
- const env = resolveEnv();
206
+ const { env, debugLabel: envDebug } = resolveEnv();
204
207
  const platform = resolvePlatform();
205
- const debug = `platform=${platform ?? "none"} | source=${source} | url=${parsed.origin} | env=${env}`;
206
- return {
208
+ const debug = `${urlDebug} | env=${env} (${envDebug})`;
209
+ const result = {
207
210
  href: parsed.origin,
208
211
  origin: parsed.origin,
209
212
  hostname: parsed.hostname,
@@ -212,19 +215,24 @@ function resolve() {
212
215
  port: parsed.port,
213
216
  env,
214
217
  platform,
215
- source,
216
218
  debug,
217
219
  isProduction: env === "production",
218
220
  isPreview: env === "preview",
219
221
  isLocal: env === "local"
220
222
  };
223
+ Object.defineProperty(result, "debug", {
224
+ value: debug,
225
+ enumerable: false,
226
+ configurable: false
227
+ });
228
+ return result;
221
229
  }
222
230
  var _resolved;
223
231
  try {
224
232
  _resolved = resolve();
225
233
  } catch (e) {
226
234
  console.warn(`[which-url] Could not detect app URL. Set APP_URL (e.g. APP_URL=https://myapp.com or APP_URL=myapp.com)`);
227
- _resolved = {
235
+ const fallback = {
228
236
  href: "",
229
237
  origin: "",
230
238
  hostname: "",
@@ -233,12 +241,17 @@ try {
233
241
  port: "",
234
242
  env: "local",
235
243
  platform: null,
236
- source: null,
237
- debug: "platform=none | source=none | url=none | env=local",
244
+ debug: "[error] resolution failed",
238
245
  isProduction: false,
239
246
  isPreview: false,
240
247
  isLocal: true
241
248
  };
249
+ Object.defineProperty(fallback, "debug", {
250
+ value: "[error] resolution failed",
251
+ enumerable: false,
252
+ configurable: false
253
+ });
254
+ _resolved = fallback;
242
255
  }
243
256
  var href = _resolved.href;
244
257
  var origin = _resolved.origin;
@@ -248,14 +261,11 @@ var protocol = _resolved.protocol;
248
261
  var port = _resolved.port;
249
262
  var env = _resolved.env;
250
263
  var platform = _resolved.platform;
251
- var source = _resolved.source;
252
- var debug = _resolved.debug;
253
264
  var isProduction = _resolved.isProduction;
254
265
  var isPreview = _resolved.isPreview;
255
266
  var isLocal = _resolved.isLocal;
256
267
  var src_default = _resolved;
257
268
  export {
258
- source,
259
269
  protocol,
260
270
  port,
261
271
  platform,
@@ -267,6 +277,5 @@ export {
267
277
  hostname,
268
278
  host,
269
279
  env,
270
- src_default as default,
271
- debug
280
+ src_default as default
272
281
  };
package/dist/resolve.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { Platform, Source } from "./types";
1
+ import type { Platform } from "./types";
2
2
  export interface ResolveResult {
3
3
  url: string;
4
- source: Source;
4
+ debugLabel: string;
5
5
  }
6
6
  export declare function resolveUrl(): ResolveResult;
7
7
  export declare function resolvePlatform(): Platform;
@@ -1 +1 @@
1
- {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAE/C,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;CACf;AAED,wBAAgB,UAAU,IAAI,aAAa,CA+B1C;AAED,wBAAgB,eAAe,IAAI,QAAQ,CAQ1C"}
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAA;IACX,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,UAAU,IAAI,aAAa,CAkC1C;AAED,wBAAgB,eAAe,IAAI,QAAQ,CAQ1C"}
package/dist/types.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export type AppEnv = "production" | "preview" | "local";
2
2
  export type Platform = "vercel" | "netlify" | "cloudflare" | "railway" | "fly" | "render" | "digitalocean" | "heroku" | null;
3
- export type Source = "override" | "provider" | "browser" | "fallback" | null;
4
3
  export interface WhichUrl {
5
4
  href: string;
6
5
  origin: string;
@@ -10,7 +9,6 @@ export interface WhichUrl {
10
9
  port: string;
11
10
  env: AppEnv;
12
11
  platform: Platform;
13
- source: Source;
14
12
  debug: string;
15
13
  isProduction: boolean;
16
14
  isPreview: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG,YAAY,GAAG,SAAS,GAAG,OAAO,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GACZ,SAAS,GACT,KAAK,GACL,QAAQ,GACR,cAAc,GACd,QAAQ,GACR,IAAI,CAAA;AAER,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,QAAQ,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,EAAE,OAAO,CAAA;IACrB,SAAS,EAAE,OAAO,CAAA;IAClB,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,KAAK,OAAO,CAAA;IAC5D,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,KAAK,MAAM,GAAG,IAAI,CAAA;IACtE,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,KAAK,MAAM,CAAA;CAChE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "which-url",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Auto-detect your app's URL across hosting providers. Zero config.",
5
5
  "type": "module",
6
6
  "exports": {