Skip to content

Commit

Permalink
fix(cache): proper root filename handling for subfolders (#2305)
Browse files Browse the repository at this point in the history
  • Loading branch information
kptdobe authored Jan 25, 2024
1 parent 2fe8f7f commit e7e2d34
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/server/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ window.LiveReloadOptions = {
computePathForCache(url, directory) {
const u = new URL(url);
const { pathname, search } = u;
let fileName = pathname.substring(1) || 'index.html';
let fileName = pathname.substring(1);
if (fileName.endsWith('/') || fileName === '') {
fileName += 'index.html';
}
if (search) {
let qs = search.substring(1); // remove leading '?'
if (fileName.length + qs.length > 255) {
Expand Down
2 changes: 2 additions & 0 deletions test/server-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ describe('Utils Test', () => {

describe('Cache', () => {
it('compute path for cache', () => {
assert.equal(utils.computePathForCache('https://www.sample.com/', '/target/'), path.resolve('/target', 'index.html'));
assert.equal(utils.computePathForCache('https://www.sample.com/folder/', '/target/'), path.resolve('/target/folder', 'index.html'));
assert.equal(utils.computePathForCache('https://www.sample.com/index.html', '/target/'), path.resolve('/target', 'index.html'));
assert.equal(utils.computePathForCache('https://www.sample.com/folder/index.html', '/target/'), path.resolve('/target', 'folder/index.html'));
assert.equal(utils.computePathForCache('https://www.sample.com/script.js', '/target/'), path.resolve('/target', 'script.js'));
Expand Down

0 comments on commit e7e2d34

Please sign in to comment.