Skip to content

Commit

Permalink
Attempt to avoid redirects when an asset isn't found
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadorequest committed May 15, 2020
1 parent b52802b commit fad1e2d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const i18nConfig = require('./src/i18nConfig');
const supportedLocales = i18nConfig.supportedLocales.map((supportedLocale) => {
return supportedLocale.name;
});
const publicBasePaths = ['robots', 'static', 'favicon.ico']; // All items (folders, files) under /public directory should be added there, to avoid redirection when an asset isn't found
const noRedirectBasePaths = [...supportedLocales, ...publicBasePaths]; // Will disable url rewrite for those items (should contain all supported languages and all public base paths)

console.debug(`Building Next with NODE_ENV="${process.env.NODE_ENV}" APP_STAGE="${process.env.APP_STAGE}" for CUSTOMER_REF="${process.env.CUSTOMER_REF}"`);

Expand Down Expand Up @@ -61,7 +63,7 @@ module.exports = withSourceMaps({
destination: '/api/autoRedirectToLocalisedPage',
},
{
source: `/:locale((?!${supportedLocales.join('|')})[^/]+)(.*)`,
source: `/:locale((?!${noRedirectBasePaths.join('|')})[^/]+)(.*)`,
destination: '/api/autoRedirectToLocalisedPage',
},
];
Expand Down

0 comments on commit fad1e2d

Please sign in to comment.