summaryrefslogtreecommitdiff
path: root/packages/integrations/node/src/serve-static.ts
diff options
context:
space:
mode:
authorGravatar Andrés Correa Casablanca <castarco@coderspirit.xyz> 2024-03-19 16:43:08 +0100
committerGravatar GitHub <noreply@github.com> 2024-03-19 21:13:08 +0530
commitfd7be674ef4070a9d919a4910b8520936dd55f6a (patch)
tree9ac8d9012348ecdd09e93f984dc8b1037d42d6aa /packages/integrations/node/src/serve-static.ts
parente25aa3af17ba85ed326333e3e09e5c1680566123 (diff)
downloadastro-fd7be674ef4070a9d919a4910b8520936dd55f6a.tar.gz
astro-fd7be674ef4070a9d919a4910b8520936dd55f6a.tar.zst
astro-fd7be674ef4070a9d919a4910b8520936dd55f6a.zip
fix: do not append trailing slash to subresource urls (#10491)
* fix: do not append traling slash to subresource urls Signed-off-by: Andres Correa Casablanca <andreu@kindspells.dev> * test: fix broken test Signed-off-by: Andres Correa Casablanca <andreu@kindspells.dev> * refactor: packages/integrations/node/src/serve-static.ts Co-authored-by: Arsh <69170106+lilnasy@users.noreply.github.com> --------- Signed-off-by: Andres Correa Casablanca <andreu@kindspells.dev> Co-authored-by: Arsh <69170106+lilnasy@users.noreply.github.com>
Diffstat (limited to 'packages/integrations/node/src/serve-static.ts')
-rw-r--r--packages/integrations/node/src/serve-static.ts6
1 files changed, 5 insertions, 1 deletions
diff --git a/packages/integrations/node/src/serve-static.ts b/packages/integrations/node/src/serve-static.ts
index a65e52e96..811f748a4 100644
--- a/packages/integrations/node/src/serve-static.ts
+++ b/packages/integrations/node/src/serve-static.ts
@@ -6,6 +6,9 @@ import type { NodeApp } from 'astro/app/node';
import send from 'send';
import type { Options } from './types.js';
+// check for a dot followed by a extension made up of lowercase characters
+const isSubresourceRegex = /.+\.[a-z]+$/i
+
/**
* Creates a Node.js http listener for static files and prerendered pages.
* In standalone mode, the static handler is queried first for the static files.
@@ -48,7 +51,8 @@ export function createStaticHandler(app: NodeApp, options: Options) {
}
break;
case 'always':
- if (!hasSlash) {
+ // trailing slash is not added to "subresources"
+ if (!hasSlash && !urlPath.match(isSubresourceRegex)) {
pathname = urlPath + '/' + (urlQuery ? '?' + urlQuery : '');
res.statusCode = 301;
res.setHeader('Location', pathname);