Skip to content

Commit 3fc1966

Browse files
author
Ruslan Matkovskyi
committed
[sitecore-jss-nextjs]: Removed a method that addressed Netlify issues. Added a simpler solution for non-regex patterns to fix Netlify-related problems. Improved redirect performance.
1 parent 48f55f3 commit 3fc1966

File tree

5 files changed

+317
-270
lines changed

5 files changed

+317
-270
lines changed

packages/sitecore-jss-nextjs/src/middleware/redirects-middleware.test.ts

+1-52
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ describe('RedirectsMiddleware', () => {
822822
request: {
823823
nextUrl: {
824824
pathname: '/not-found',
825-
search: 'abc=def',
825+
search: '',
826826
href: 'http://localhost:3000/not-found',
827827
locale: 'en',
828828
origin: 'http://localhost:3000',
@@ -1361,57 +1361,6 @@ describe('RedirectsMiddleware', () => {
13611361
expect(finalRes.status).to.equal(res.status);
13621362
});
13631363

1364-
it('should return 301 redirect when queryString is ordered by alphabetic(Netlify feature)', async () => {
1365-
const cloneUrl = () => Object.assign({}, req.nextUrl);
1366-
const url = {
1367-
clone: cloneUrl,
1368-
href: 'http://localhost:3000/found?a=1&w=1',
1369-
locale: 'en',
1370-
origin: 'http://localhost:3000',
1371-
search: '?a=1&w=1',
1372-
pathname: '/found',
1373-
};
1374-
1375-
const { res, req } = createTestRequestResponse({
1376-
response: { url },
1377-
request: {
1378-
nextUrl: {
1379-
pathname: '/not-found/',
1380-
search: '?a=1&w=1',
1381-
href: 'http://localhost:3000/not-found/?a=1&w=1',
1382-
locale: 'en',
1383-
origin: 'http://localhost:3000',
1384-
clone: cloneUrl,
1385-
},
1386-
},
1387-
});
1388-
setupRedirectStub(301);
1389-
1390-
const { finalRes, fetchRedirects, siteResolver } = await runTestWithRedirect(
1391-
{
1392-
pattern: '/not-found?w=1&a=1',
1393-
target: '/found',
1394-
redirectType: REDIRECT_TYPE_301,
1395-
isQueryStringPreserved: true,
1396-
locale: 'en',
1397-
},
1398-
req
1399-
);
1400-
1401-
validateEndMessageDebugLog('redirects middleware end in %dms: %o', {
1402-
headers: {},
1403-
redirected: undefined,
1404-
status: 301,
1405-
url,
1406-
});
1407-
1408-
expect(siteResolver.getByHost).to.be.calledWith(hostname);
1409-
// eslint-disable-next-line no-unused-expressions
1410-
expect(fetchRedirects.called).to.be.true;
1411-
expect(finalRes).to.deep.equal(res);
1412-
expect(finalRes.status).to.equal(res.status);
1413-
});
1414-
14151364
it('should return 301 redirect when pattern has special symbols "?"', async () => {
14161365
const cloneUrl = () => Object.assign({}, req.nextUrl);
14171366
const url = {

0 commit comments

Comments
 (0)