Skip to content

Commit

Permalink
Merge pull request #32 from ladjs/fix/sourcemaps
Browse files Browse the repository at this point in the history
fix: check for sourcemap statics
  • Loading branch information
shadowgate15 authored Nov 17, 2021
2 parents 6e8e175 + 92b80b0 commit 4d61b77
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,14 @@ class I18N {
if (extname(ctx.path) !== '') {
if (!this.config.redirectTLDS) return next();
const asciiFile = toASCII(basename(ctx.path));
if (!punycodedTlds.some((tld) => asciiFile.endsWith(`.${tld}`)))

// do a speciality check for .js.map and .css.map
// since .map is in tlds
if (
!punycodedTlds.some((tld) => asciiFile.endsWith(`.${tld}`)) ||
asciiFile.endsWith('.js.map') ||
asciiFile.endsWith('.css.map')
)
return next();
}

Expand Down
25 changes: 25 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,31 @@ test('does not redirect to static paths', async (t) => {
t.is(res.status, 200);
});

test('does not redirect to static sourcemap paths', async (t) => {
const app = new Koa();
const i18n = new I18N({ phrases, directory });

app.use(session());
app.use(i18n.middleware);
app.use(i18n.redirect);

app.use((ctx) => {
const { locale } = ctx;
ctx.body = { locale };
ctx.status = 200;
});

let res = await request(app.listen())
.get('/login.css.map')
.set('Cookie', ['locale=es']);
t.is(res.status, 200);

res = await request(app.listen())
.get('/login.js.map')
.set('Cookie', ['locale=es']);
t.is(res.status, 200);
});

test('does not redirect typical domain extension when disabled', async (t) => {
const app = new Koa();
const i18n = new I18N({ phrases, directory, redirectTLDS: false });
Expand Down

0 comments on commit 4d61b77

Please sign in to comment.