Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not append trailing slash to subresource urls #10491

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: do not append traling slash to subresource urls
Signed-off-by: Andres Correa Casablanca <andreu@kindspells.dev>
  • Loading branch information
castarco committed Mar 19, 2024
commit 0abf85184d77af7ba2e2e74cf77e4c4ec5b4ffff
5 changes: 5 additions & 0 deletions .changeset/tender-snails-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/node": patch
---

fix: do not append traling slash to subresource urls
castarco marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion packages/integrations/node/src/serve-static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export function createStaticHandler(app: NodeApp, options: Options) {
}
break;
case 'always':
if (!hasSlash) {
// trailing slash is not added to "subresources"
if (!hasSlash && !urlPath.match(/.+\.[a-z]+$/i)) {
castarco marked this conversation as resolved.
Show resolved Hide resolved
pathname = urlPath + '/' + (urlQuery ? '?' + urlQuery : '');
res.statusCode = 301;
res.setHeader('Location', pathname);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
h1 { color: red; }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { after, before, describe, it, expect } from 'node:test';
import * as cheerio from 'cheerio';
import nodejs from '../dist/index.js';
import { loadFixture } from './test-utils.js';
Expand Down Expand Up @@ -76,6 +76,14 @@ describe('Trailing slash', () => {
expect(res.status).to.equal(200);
expect($('h1').text()).to.equal('One');
});

it('Does not add trailing slash to subresource urls', async () => {
const res = await fetch(`http://${server.host}:${server.port}/some-base/one.css`);
const css = await res.text();

expect(res.status).to.equal(200);
expect(css).to.equal('h1 { color: red; }\n');
castarco marked this conversation as resolved.
Show resolved Hide resolved
})
});
describe('Without base', async () => {
before(async () => {
Expand Down Expand Up @@ -133,6 +141,14 @@ describe('Trailing slash', () => {
expect(res.status).to.equal(200);
expect($('h1').text()).to.equal('One');
});

it('Does not add trailing slash to subresource urls', async () => {
const res = await fetch(`http://${server.host}:${server.port}/one.css`);
const css = await res.text();

expect(res.status).to.equal(200);
expect(css).to.equal('h1 { color: red; }\n');
})
});
});
describe('Never', async () => {
Expand Down
Loading