@bleedingdev/modern-js-app-tools 3.2.0-ultramodern.69 → 3.2.0-ultramodern.70

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.
@@ -67,6 +67,20 @@ function normalizeRoutePath(pathname) {
67
67
  if ('/' === pathname) return pathname;
68
68
  return pathname.replace(/\/+$/u, '');
69
69
  }
70
+ function getPathExtension(pathname) {
71
+ const lastSegment = pathname.split('/').pop() || '';
72
+ const dotIndex = lastSegment.lastIndexOf('.');
73
+ if (dotIndex <= 0 || dotIndex === lastSegment.length - 1) return '';
74
+ return lastSegment.slice(dotIndex).toLowerCase();
75
+ }
76
+ function isAssetLikePathname(pathname) {
77
+ const extension = getPathExtension(pathname);
78
+ return '' !== extension && '.html' !== extension && '.htm' !== extension;
79
+ }
80
+ function routeMatchesExactly(route, pathname) {
81
+ if ('string' != typeof route?.urlPath) return false;
82
+ return normalizeRoutePath(route.urlPath) === normalizeRoutePath(pathname);
83
+ }
70
84
  function routeMatches(route, pathname) {
71
85
  if ('string' != typeof route.urlPath) return false;
72
86
  const routePath = normalizeRoutePath(route.urlPath);
@@ -389,6 +403,10 @@ export default {
389
403
  const bffResponse = await dispatchBffRequest(request, env);
390
404
  if (bffResponse) return withCorsHeaders(bffResponse);
391
405
  const route = findRoute(request);
406
+ const { pathname } = new URL(request.url);
407
+ if (isAssetLikePathname(pathname) && !routeMatchesExactly(route, pathname)) return withCorsHeaders(new Response('Not found', {
408
+ status: 404
409
+ }));
392
410
  if (route?.worker) return withCorsHeaders(await dispatchRouteWorker(route, request, env, ctx));
393
411
  const htmlResponse = await fetchRouteHtml(route, request, env);
394
412
  if (htmlResponse) return htmlResponse;
@@ -67,6 +67,20 @@ function normalizeRoutePath(pathname) {
67
67
  if ('/' === pathname) return pathname;
68
68
  return pathname.replace(/\/+$/u, '');
69
69
  }
70
+ function getPathExtension(pathname) {
71
+ const lastSegment = pathname.split('/').pop() || '';
72
+ const dotIndex = lastSegment.lastIndexOf('.');
73
+ if (dotIndex <= 0 || dotIndex === lastSegment.length - 1) return '';
74
+ return lastSegment.slice(dotIndex).toLowerCase();
75
+ }
76
+ function isAssetLikePathname(pathname) {
77
+ const extension = getPathExtension(pathname);
78
+ return '' !== extension && '.html' !== extension && '.htm' !== extension;
79
+ }
80
+ function routeMatchesExactly(route, pathname) {
81
+ if ('string' != typeof route?.urlPath) return false;
82
+ return normalizeRoutePath(route.urlPath) === normalizeRoutePath(pathname);
83
+ }
70
84
  function routeMatches(route, pathname) {
71
85
  if ('string' != typeof route.urlPath) return false;
72
86
  const routePath = normalizeRoutePath(route.urlPath);
@@ -389,6 +403,10 @@ export default {
389
403
  const bffResponse = await dispatchBffRequest(request, env);
390
404
  if (bffResponse) return withCorsHeaders(bffResponse);
391
405
  const route = findRoute(request);
406
+ const { pathname } = new URL(request.url);
407
+ if (isAssetLikePathname(pathname) && !routeMatchesExactly(route, pathname)) return withCorsHeaders(new Response('Not found', {
408
+ status: 404
409
+ }));
392
410
  if (route?.worker) return withCorsHeaders(await dispatchRouteWorker(route, request, env, ctx));
393
411
  const htmlResponse = await fetchRouteHtml(route, request, env);
394
412
  if (htmlResponse) return htmlResponse;
@@ -67,6 +67,20 @@ function normalizeRoutePath(pathname) {
67
67
  if ('/' === pathname) return pathname;
68
68
  return pathname.replace(/\/+$/u, '');
69
69
  }
70
+ function getPathExtension(pathname) {
71
+ const lastSegment = pathname.split('/').pop() || '';
72
+ const dotIndex = lastSegment.lastIndexOf('.');
73
+ if (dotIndex <= 0 || dotIndex === lastSegment.length - 1) return '';
74
+ return lastSegment.slice(dotIndex).toLowerCase();
75
+ }
76
+ function isAssetLikePathname(pathname) {
77
+ const extension = getPathExtension(pathname);
78
+ return '' !== extension && '.html' !== extension && '.htm' !== extension;
79
+ }
80
+ function routeMatchesExactly(route, pathname) {
81
+ if ('string' != typeof route?.urlPath) return false;
82
+ return normalizeRoutePath(route.urlPath) === normalizeRoutePath(pathname);
83
+ }
70
84
  function routeMatches(route, pathname) {
71
85
  if ('string' != typeof route.urlPath) return false;
72
86
  const routePath = normalizeRoutePath(route.urlPath);
@@ -389,6 +403,10 @@ export default {
389
403
  const bffResponse = await dispatchBffRequest(request, env);
390
404
  if (bffResponse) return withCorsHeaders(bffResponse);
391
405
  const route = findRoute(request);
406
+ const { pathname } = new URL(request.url);
407
+ if (isAssetLikePathname(pathname) && !routeMatchesExactly(route, pathname)) return withCorsHeaders(new Response('Not found', {
408
+ status: 404
409
+ }));
392
410
  if (route?.worker) return withCorsHeaders(await dispatchRouteWorker(route, request, env, ctx));
393
411
  const htmlResponse = await fetchRouteHtml(route, request, env);
394
412
  if (htmlResponse) return htmlResponse;
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.2.0-ultramodern.69",
20
+ "version": "3.2.0-ultramodern.70",
21
21
  "types": "./dist/types/index.d.ts",
22
22
  "main": "./dist/cjs/index.js",
23
23
  "exports": {
@@ -99,16 +99,16 @@
99
99
  "ndepe": "^0.1.13",
100
100
  "pkg-types": "^2.3.1",
101
101
  "std-env": "4.1.0",
102
- "@modern-js/i18n-utils": "npm:@bleedingdev/modern-js-i18n-utils@3.2.0-ultramodern.69",
103
- "@modern-js/builder": "npm:@bleedingdev/modern-js-builder@3.2.0-ultramodern.69",
104
- "@modern-js/prod-server": "npm:@bleedingdev/modern-js-prod-server@3.2.0-ultramodern.69",
105
- "@modern-js/plugin-data-loader": "npm:@bleedingdev/modern-js-plugin-data-loader@3.2.0-ultramodern.69",
106
- "@modern-js/server": "npm:@bleedingdev/modern-js-server@3.2.0-ultramodern.69",
107
- "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.2.0-ultramodern.69",
108
- "@modern-js/server-utils": "npm:@bleedingdev/modern-js-server-utils@3.2.0-ultramodern.69",
109
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.69",
110
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.69",
111
- "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.69"
102
+ "@modern-js/i18n-utils": "npm:@bleedingdev/modern-js-i18n-utils@3.2.0-ultramodern.70",
103
+ "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.70",
104
+ "@modern-js/builder": "npm:@bleedingdev/modern-js-builder@3.2.0-ultramodern.70",
105
+ "@modern-js/prod-server": "npm:@bleedingdev/modern-js-prod-server@3.2.0-ultramodern.70",
106
+ "@modern-js/plugin-data-loader": "npm:@bleedingdev/modern-js-plugin-data-loader@3.2.0-ultramodern.70",
107
+ "@modern-js/server": "npm:@bleedingdev/modern-js-server@3.2.0-ultramodern.70",
108
+ "@modern-js/server-utils": "npm:@bleedingdev/modern-js-server-utils@3.2.0-ultramodern.70",
109
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.70",
110
+ "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.2.0-ultramodern.70",
111
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.70"
112
112
  },
113
113
  "devDependencies": {
114
114
  "@rslib/core": "0.21.5",