which-url 0.0.6 → 0.0.7
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 +11 -5
- package/dist/env-var.d.ts.map +1 -1
- package/dist/index.d.ts +27 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -4
- package/dist/resolve.d.ts.map +1 -1
- package/dist/types.d.ts +29 -14
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -160,6 +160,8 @@ Zero config — [portless](https://portless.sh) sets `PORTLESS_URL` and `which-u
|
|
|
160
160
|
origin → https://myapp.localhost
|
|
161
161
|
```
|
|
162
162
|
|
|
163
|
+
When sharing via Tailscale (`portless run --tailscale`), `PORTLESS_TAILSCALE_URL` takes priority so `origin` returns the publicly-reachable URL.
|
|
164
|
+
|
|
163
165
|
### Tunnels (ngrok, Cloudflare Tunnel)
|
|
164
166
|
|
|
165
167
|
Tunnel URLs can't be auto-detected — they're external to the app process. Set `APP_URL`:
|
|
@@ -182,10 +184,13 @@ Modern wrangler polyfills `process.env` from `[vars]`, so `which-url` picks it u
|
|
|
182
184
|
### Debugging
|
|
183
185
|
|
|
184
186
|
```typescript
|
|
185
|
-
import
|
|
187
|
+
import appUrl from 'which-url'
|
|
186
188
|
|
|
187
|
-
console.log(debug)
|
|
188
|
-
// "
|
|
189
|
+
console.log(appUrl.debug)
|
|
190
|
+
// "[provider:vercel] url=myapp.com | env=production (vercel:production)"
|
|
191
|
+
// "[override] APP_URL=https://custom.com | env=production (NODE_ENV=production)"
|
|
192
|
+
// "[portless] PORTLESS_URL=https://myapp.localhost | env=local (NODE_ENV=development)"
|
|
193
|
+
// "[fallback] PORT=3004 | env=local (NODE_ENV=development)"
|
|
189
194
|
```
|
|
190
195
|
|
|
191
196
|
## API
|
|
@@ -206,8 +211,9 @@ An object with URL properties and environment helpers.
|
|
|
206
211
|
| `port` | `string` | `""` or `"3000"` |
|
|
207
212
|
| `env` | `AppEnv` | `"production"` \| `"preview"` \| `"local"` |
|
|
208
213
|
| `platform` | `Platform` | `"vercel"` \| `"netlify"` \| ... \| `null` |
|
|
209
|
-
| `
|
|
210
|
-
|
|
214
|
+
| `debug`* | `string` | `"[provider:vercel] url=myapp.com \| env=production (vercel:production)"` |
|
|
215
|
+
|
|
216
|
+
\* `debug` is non-enumerable — excluded from `JSON.stringify` to avoid React hydration mismatches. Access via `appUrl.debug`.
|
|
211
217
|
| `isProduction` | `boolean` | |
|
|
212
218
|
| `isPreview` | `boolean` | |
|
|
213
219
|
| `isLocal` | `boolean` | |
|
package/dist/env-var.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-var.d.ts","sourceRoot":"","sources":["../src/env-var.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"env-var.d.ts","sourceRoot":"","sources":["../src/env-var.ts"],"names":[],"mappings":"AAkGA;;;;;;;GAOG;AACH,wBAAgB,MAAM,CACpB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,EACvC,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,SAAS,CA4BpB;AAED,wBAAgB,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAK3D"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,40 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
declare let _resolved:
|
|
1
|
+
import type { WhichUrlWithDebug, AppEnv, Platform } from "./types";
|
|
2
|
+
declare let _resolved: WhichUrlWithDebug;
|
|
3
|
+
/** Full URL including protocol — `"https://myapp.com"` */
|
|
3
4
|
export declare const href: string;
|
|
5
|
+
/** Full origin — `"https://myapp.com"` (same as href) */
|
|
4
6
|
export declare const origin: string;
|
|
7
|
+
/** Hostname without port — `"myapp.com"` */
|
|
5
8
|
export declare const hostname: string;
|
|
9
|
+
/** Hostname with port — `"myapp.com"` or `"localhost:3000"` */
|
|
6
10
|
export declare const host: string;
|
|
11
|
+
/** Protocol with colon — `"https:"` or `"http:"` */
|
|
7
12
|
export declare const protocol: string;
|
|
13
|
+
/** Port string — `""` for default ports, `"3000"` for custom */
|
|
8
14
|
export declare const port: string;
|
|
15
|
+
/** Current environment — `"production"`, `"preview"`, or `"local"` */
|
|
9
16
|
export declare const env: AppEnv;
|
|
17
|
+
/** Detected hosting platform — `"vercel"`, `"netlify"`, etc. or `null` */
|
|
10
18
|
export declare const platform: Platform;
|
|
19
|
+
/** `true` when running in production */
|
|
11
20
|
export declare const isProduction: boolean;
|
|
21
|
+
/** `true` when running in a preview/staging deployment */
|
|
12
22
|
export declare const isPreview: boolean;
|
|
23
|
+
/** `true` when running locally (development) */
|
|
13
24
|
export declare const isLocal: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Auto-detected app URL with environment metadata.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import appUrl from 'which-url'
|
|
31
|
+
*
|
|
32
|
+
* appUrl.origin // "https://myapp.com"
|
|
33
|
+
* appUrl.env // "production"
|
|
34
|
+
* appUrl.platform // "vercel"
|
|
35
|
+
* appUrl.debug // "[provider:vercel] url=myapp.com | env=production (vercel:production)"
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
14
38
|
export default _resolved;
|
|
15
|
-
export type { WhichUrl, AppEnv, Platform };
|
|
39
|
+
export type { WhichUrl, WhichUrlWithDebug, AppEnv, Platform, PlatformName } from "./types";
|
|
16
40
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAA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CEL_ENV":
|
|
@@ -13,13 +21,17 @@ function readStatic(name) {
|
|
|
13
21
|
return process.env.APP_URL || process.env.NEXT_PUBLIC_APP_URL || process.env.NUXT_ENV_APP_URL || process.env.VITE_APP_URL || process.env.PUBLIC_APP_URL || process.env.REACT_APP_APP_URL || process.env.GATSBY_APP_URL || process.env.VUE_APP_APP_URL || process.env.REDWOOD_ENV_APP_URL || process.env.SANITY_STUDIO_APP_URL || undefined;
|
|
14
22
|
case "APP_ENV":
|
|
15
23
|
return process.env.APP_ENV || process.env.NEXT_PUBLIC_APP_ENV || process.env.NUXT_ENV_APP_ENV || process.env.VITE_APP_ENV || process.env.PUBLIC_APP_ENV || process.env.REACT_APP_APP_ENV || process.env.GATSBY_APP_ENV || process.env.VUE_APP_APP_ENV || process.env.REDWOOD_ENV_APP_ENV || process.env.SANITY_STUDIO_APP_ENV || undefined;
|
|
24
|
+
default:
|
|
25
|
+
return;
|
|
16
26
|
}
|
|
17
27
|
}
|
|
18
28
|
function getVar(env, name) {
|
|
19
29
|
if (typeof process !== "undefined" && process?.env && env === process.env) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
30
|
+
if (ENV_VARS.includes(name)) {
|
|
31
|
+
const val = readStatic(name);
|
|
32
|
+
if (val)
|
|
33
|
+
return val;
|
|
34
|
+
}
|
|
23
35
|
}
|
|
24
36
|
const PREFIXES = [
|
|
25
37
|
"",
|
|
@@ -149,8 +161,12 @@ function resolveUrl() {
|
|
|
149
161
|
const override = getVar(env, "APP_URL");
|
|
150
162
|
if (override)
|
|
151
163
|
return { url: normalizeUrl(override), debugLabel: `[override] APP_URL=${override}` };
|
|
152
|
-
if (env.
|
|
164
|
+
if (env.PORTLESS_TAILSCALE_URL) {
|
|
165
|
+
return { url: env.PORTLESS_TAILSCALE_URL, debugLabel: `[portless:tailscale] PORTLESS_TAILSCALE_URL=${env.PORTLESS_TAILSCALE_URL}` };
|
|
166
|
+
}
|
|
167
|
+
if (env.PORTLESS_URL) {
|
|
153
168
|
return { url: env.PORTLESS_URL, debugLabel: `[portless] PORTLESS_URL=${env.PORTLESS_URL}` };
|
|
169
|
+
}
|
|
154
170
|
for (const p of providers) {
|
|
155
171
|
if (p.detect(env)) {
|
|
156
172
|
const url = p.resolveUrl(env);
|
package/dist/resolve.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,CAuC1C;AAED,wBAAgB,eAAe,IAAI,QAAQ,CAQ1C"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,21 +1,36 @@
|
|
|
1
1
|
export type AppEnv = "production" | "preview" | "local";
|
|
2
|
-
export type
|
|
2
|
+
export type PlatformName = "vercel" | "netlify" | "cloudflare" | "railway" | "fly" | "render" | "digitalocean" | "heroku";
|
|
3
|
+
export type Platform = PlatformName | null;
|
|
3
4
|
export interface WhichUrl {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
/** Full URL including protocol — `"https://myapp.com"` */
|
|
6
|
+
readonly href: string;
|
|
7
|
+
/** Full origin — `"https://myapp.com"` (same as href) */
|
|
8
|
+
readonly origin: string;
|
|
9
|
+
/** Hostname without port — `"myapp.com"` */
|
|
10
|
+
readonly hostname: string;
|
|
11
|
+
/** Hostname with port — `"myapp.com"` or `"localhost:3000"` */
|
|
12
|
+
readonly host: string;
|
|
13
|
+
/** Protocol with colon — `"https:"` or `"http:"` */
|
|
14
|
+
readonly protocol: string;
|
|
15
|
+
/** Port string — `""` for default ports, `"3000"` for custom */
|
|
16
|
+
readonly port: string;
|
|
17
|
+
/** Current environment — `"production"`, `"preview"`, or `"local"` */
|
|
18
|
+
readonly env: AppEnv;
|
|
19
|
+
/** Detected hosting platform — `"vercel"`, `"netlify"`, etc. or `null` */
|
|
20
|
+
readonly platform: Platform;
|
|
21
|
+
/** `true` when running in production */
|
|
22
|
+
readonly isProduction: boolean;
|
|
23
|
+
/** `true` when running in a preview/staging deployment */
|
|
24
|
+
readonly isPreview: boolean;
|
|
25
|
+
/** `true` when running locally (development) */
|
|
26
|
+
readonly isLocal: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface WhichUrlWithDebug extends WhichUrl {
|
|
29
|
+
/** Resolution debug string (non-enumerable — excluded from JSON.stringify and object spread). */
|
|
30
|
+
readonly debug: string;
|
|
16
31
|
}
|
|
17
32
|
export interface ProviderDetector {
|
|
18
|
-
name:
|
|
33
|
+
name: PlatformName;
|
|
19
34
|
detect: (env: Record<string, string | undefined>) => boolean;
|
|
20
35
|
resolveUrl: (env: Record<string, string | undefined>) => string | null;
|
|
21
36
|
resolveEnv: (env: Record<string, string | undefined>) => AppEnv;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -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,CAAA;AAEvD,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRo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