Skip to content

Commit

Permalink
Return 404 when current locale isn't allowed (it's already the defaul…
Browse files Browse the repository at this point in the history
…t behavior in production, but not in dev nor preview)
  • Loading branch information
Vadorequest committed May 28, 2021
1 parent a48b7f6 commit e715d46
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/layouts/core/coreLayoutSSG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
ApolloQueryResult,
NormalizedCacheObject,
} from '@apollo/client';
import includes from 'lodash.includes';
import map from 'lodash.map';
import {
GetStaticPaths,
Expand Down Expand Up @@ -149,6 +150,15 @@ export const getCoreStaticProps: GetStaticProps<SSGPageProps, CommonServerSidePa
customer,
};

// Do not serve pages using locales the customer doesn't have enabled (useful during preview mode and in development env)
if (!includes(customer?.availableLanguages, locale)) {
logger.warn(`Locale "${locale}" not enabled for this customer (allowed: "${customer?.availableLanguages}"), returning 404 page.`);

return {
notFound: true,
};
}

return {
// Props returned here will be available as page properties (pageProps)
props: {
Expand Down
10 changes: 10 additions & 0 deletions src/layouts/demo/demoLayoutSSG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
ApolloQueryResult,
NormalizedCacheObject,
} from '@apollo/client';
import includes from 'lodash.includes';
import map from 'lodash.map';
import {
GetStaticPaths,
Expand Down Expand Up @@ -149,6 +150,15 @@ export const getDemoStaticProps: GetStaticProps<SSGPageProps, CommonServerSidePa
customer,
};

// Do not serve pages using locales the customer doesn't have enabled (useful during preview mode and in development env)
if (!includes(customer?.availableLanguages, locale)) {
logger.warn(`Locale "${locale}" not enabled for this customer (allowed: "${customer?.availableLanguages}"), returning 404 page.`);

return {
notFound: true,
};
}

return {
// Props returned here will be available as page properties (pageProps)
props: {
Expand Down

0 comments on commit e715d46

Please sign in to comment.