@bleedingdev/modern-js-app-tools 3.2.0-ultramodern.23 → 3.2.0-ultramodern.24

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.
@@ -16,8 +16,23 @@ async function fetchAssetByPath(pathname, request, env) {
16
16
  url.pathname = `/${pathname.replace(/^\/+/u, '')}`;
17
17
  return fetchAsset(new Request(url, request), env);
18
18
  }
19
+ async function fetchAssetByPathFollowingRedirects(pathname, request, env, visited = new Set()) {
20
+ const normalizedPathname = pathname.startsWith('/') ? pathname : `/${pathname}`;
21
+ if (visited.has(normalizedPathname)) return null;
22
+ visited.add(normalizedPathname);
23
+ const response = await fetchAssetByPath(normalizedPathname, request, env);
24
+ if (response && response.status >= 300 && response.status < 400 && response.headers.has('location')) {
25
+ const location = response.headers.get('location');
26
+ if (location) {
27
+ const nextUrl = new URL(location, request.url);
28
+ const currentUrl = new URL(request.url);
29
+ if (nextUrl.origin === currentUrl.origin) return fetchAssetByPathFollowingRedirects(nextUrl.pathname, request, env, visited);
30
+ }
31
+ }
32
+ return response;
33
+ }
19
34
  async function readAssetText(pathname, request, env) {
20
- const response = await fetchAssetByPath(pathname, request, env);
35
+ const response = await fetchAssetByPathFollowingRedirects(pathname, request, env);
21
36
  if (!response || !response.ok) return;
22
37
  return response.text();
23
38
  }
@@ -16,8 +16,23 @@ async function fetchAssetByPath(pathname, request, env) {
16
16
  url.pathname = `/${pathname.replace(/^\/+/u, '')}`;
17
17
  return fetchAsset(new Request(url, request), env);
18
18
  }
19
+ async function fetchAssetByPathFollowingRedirects(pathname, request, env, visited = new Set()) {
20
+ const normalizedPathname = pathname.startsWith('/') ? pathname : `/${pathname}`;
21
+ if (visited.has(normalizedPathname)) return null;
22
+ visited.add(normalizedPathname);
23
+ const response = await fetchAssetByPath(normalizedPathname, request, env);
24
+ if (response && response.status >= 300 && response.status < 400 && response.headers.has('location')) {
25
+ const location = response.headers.get('location');
26
+ if (location) {
27
+ const nextUrl = new URL(location, request.url);
28
+ const currentUrl = new URL(request.url);
29
+ if (nextUrl.origin === currentUrl.origin) return fetchAssetByPathFollowingRedirects(nextUrl.pathname, request, env, visited);
30
+ }
31
+ }
32
+ return response;
33
+ }
19
34
  async function readAssetText(pathname, request, env) {
20
- const response = await fetchAssetByPath(pathname, request, env);
35
+ const response = await fetchAssetByPathFollowingRedirects(pathname, request, env);
21
36
  if (!response || !response.ok) return;
22
37
  return response.text();
23
38
  }
@@ -16,8 +16,23 @@ async function fetchAssetByPath(pathname, request, env) {
16
16
  url.pathname = `/${pathname.replace(/^\/+/u, '')}`;
17
17
  return fetchAsset(new Request(url, request), env);
18
18
  }
19
+ async function fetchAssetByPathFollowingRedirects(pathname, request, env, visited = new Set()) {
20
+ const normalizedPathname = pathname.startsWith('/') ? pathname : `/${pathname}`;
21
+ if (visited.has(normalizedPathname)) return null;
22
+ visited.add(normalizedPathname);
23
+ const response = await fetchAssetByPath(normalizedPathname, request, env);
24
+ if (response && response.status >= 300 && response.status < 400 && response.headers.has('location')) {
25
+ const location = response.headers.get('location');
26
+ if (location) {
27
+ const nextUrl = new URL(location, request.url);
28
+ const currentUrl = new URL(request.url);
29
+ if (nextUrl.origin === currentUrl.origin) return fetchAssetByPathFollowingRedirects(nextUrl.pathname, request, env, visited);
30
+ }
31
+ }
32
+ return response;
33
+ }
19
34
  async function readAssetText(pathname, request, env) {
20
- const response = await fetchAssetByPath(pathname, request, env);
35
+ const response = await fetchAssetByPathFollowingRedirects(pathname, request, env);
21
36
  if (!response || !response.ok) return;
22
37
  return response.text();
23
38
  }
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.2.0-ultramodern.23",
20
+ "version": "3.2.0-ultramodern.24",
21
21
  "types": "./dist/types/index.d.ts",
22
22
  "main": "./dist/cjs/index.js",
23
23
  "exports": {
@@ -98,16 +98,16 @@
98
98
  "ndepe": "^0.1.13",
99
99
  "pkg-types": "^2.3.1",
100
100
  "std-env": "4.1.0",
101
- "@modern-js/builder": "npm:@bleedingdev/modern-js-builder@3.2.0-ultramodern.23",
102
- "@modern-js/plugin-data-loader": "npm:@bleedingdev/modern-js-plugin-data-loader@3.2.0-ultramodern.23",
103
- "@modern-js/i18n-utils": "npm:@bleedingdev/modern-js-i18n-utils@3.2.0-ultramodern.23",
104
- "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.23",
105
- "@modern-js/prod-server": "npm:@bleedingdev/modern-js-prod-server@3.2.0-ultramodern.23",
106
- "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.2.0-ultramodern.23",
107
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.23",
108
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.23",
109
- "@modern-js/server-utils": "npm:@bleedingdev/modern-js-server-utils@3.2.0-ultramodern.23",
110
- "@modern-js/server": "npm:@bleedingdev/modern-js-server@3.2.0-ultramodern.23"
101
+ "@modern-js/builder": "npm:@bleedingdev/modern-js-builder@3.2.0-ultramodern.24",
102
+ "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.24",
103
+ "@modern-js/plugin-data-loader": "npm:@bleedingdev/modern-js-plugin-data-loader@3.2.0-ultramodern.24",
104
+ "@modern-js/i18n-utils": "npm:@bleedingdev/modern-js-i18n-utils@3.2.0-ultramodern.24",
105
+ "@modern-js/prod-server": "npm:@bleedingdev/modern-js-prod-server@3.2.0-ultramodern.24",
106
+ "@modern-js/server-utils": "npm:@bleedingdev/modern-js-server-utils@3.2.0-ultramodern.24",
107
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.24",
108
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.24",
109
+ "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.2.0-ultramodern.24",
110
+ "@modern-js/server": "npm:@bleedingdev/modern-js-server@3.2.0-ultramodern.24"
111
111
  },
112
112
  "devDependencies": {
113
113
  "@rslib/core": "0.21.5",