@seip/blue-bird 0.7.4 → 0.7.5

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.
@@ -1,4 +1,7 @@
1
- const port = (import.meta.env.PORT || "3000").replace(/^["']|["']$/g, "");
1
+ const defaultPort = (import.meta.env.PORT || "3000").replace(
2
+ /^["']|["']$/g,
3
+ "",
4
+ );
2
5
  const host = (import.meta.env.HOST || "localhost").replace(/^["']|["']$/g, "");
3
6
 
4
7
  /**
@@ -7,18 +10,20 @@ const host = (import.meta.env.HOST || "localhost").replace(/^["']|["']$/g, "");
7
10
  * @param {string} [path] - API path relative to the server root (e.g. "api/users").
8
11
  * @param {URL} [requestUrl] - Current request URL (pass `Astro.url` from the page). Required in production.
9
12
  * @returns {string} Absolute URL ready for fetch.
13
+ * @example apiUrl('api/', Astro.url)
10
14
  */
11
15
  export function apiUrl(path = "", requestUrl) {
12
- if (import.meta.env.DEV) {
13
- return `http://${host}:${port}/${path}`;
14
- }
15
16
  if (!requestUrl) {
16
- throw new Error("apiUrl: requestUrl is required in production (pass Astro.url)");
17
+ throw new Error(
18
+ "apiUrl: requestUrl is required in production (pass Astro.url)",
19
+ );
17
20
  }
18
21
  const url = new URL(`/${path}`, requestUrl);
19
- if (url.hostname === "localhost") {
20
- url.hostname = "127.0.0.1";
21
- url.port = port;
22
- }
22
+ const runtimePort =
23
+ (typeof process !== "undefined" && process.env && process.env.PORT) ||
24
+ defaultPort;
25
+ url.hostname = "127.0.0.1";
26
+ url.port = runtimePort;
27
+ url.protocol = "http:";
23
28
  return url.href;
24
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seip/blue-bird",
3
- "version": "0.7.4",
3
+ "version": "0.7.5",
4
4
  "description": "Express opinionated framework with HTML rendering, API architecture, built-in JWT auth, validation, caching, and SEO",
5
5
  "type": "module",
6
6
  "exports": {