Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: docker production build #693

Merged
merged 5 commits into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ USER node
RUN yarn install --production=false --frozen-lockfile --ignore-scripts --non-interactive --no-cache

ENV BUILD_ENV=production NODE_ENV=production
RUN export "$(grep -v '^#' .env.${NEXTJS_DOTENV:-prod} | xargs -0) && yarn build"

# hadolint ignore=SC2046
RUN export $(grep -v '^#' .env.${NEXTJS_DOTENV:-prod} | xargs -0) && yarn build

# Install only prod dependencies now that we've built, to make the image smaller
RUN rm -rf node_modules/*
Expand Down
25 changes: 22 additions & 3 deletions pages/[lang]/product/[...slugOrId].js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,15 @@ function buildJSONLd(product, shop) {
function ProductDetailPage({ addItemsToCart, product, isLoadingProduct, shop }) {
const router = useRouter();
const currencyCode = (shop && shop.currency.code) || "USD";
const JSONLd = useMemo(() => buildJSONLd(product, shop), [product, shop]);
const JSONLd = useMemo(() => {
if (product && shop) {
return buildJSONLd(product, shop);
}
return null;
}, [product, shop]);

if (isLoadingProduct || router.isFallback) return <PageLoading />;
if (!product) return <Typography>Not Found</Typography>;
if (!product && !shop) return <Typography>Not Found</Typography>;

return (
<Layout shop={shop}>
Expand Down Expand Up @@ -127,10 +132,24 @@ ProductDetailPage.propTypes = {
*/
export async function getStaticProps({ params: { slugOrId, lang } }) {
const productSlug = slugOrId && slugOrId[0];
const primaryShop = await fetchPrimaryShop(lang);

if (!primaryShop) {
return {
props: {
shop: null,
translations: null,
products: null,
tags: null
},
// eslint-disable-next-line camelcase
unstable_revalidate: 1 // Revalidate immediately
};
}

return {
props: {
...await fetchPrimaryShop(lang),
...primaryShop,
...await fetchTranslations(lang, ["common", "productDetail"]),
...await fetchCatalogProduct(productSlug),
...await fetchAllTags(lang)
Expand Down
19 changes: 17 additions & 2 deletions pages/[lang]/tag/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class TagGridPage extends Component {
const pageSize = routingStore.query && routingStore.query.limit ? parseInt(routingStore.query.limit, 10) : uiStore.pageSize;
const sortBy = routingStore.query && routingStore.query.sortby ? routingStore.query.sortby : uiStore.sortBy;

if (!tag) {
if (!tag && !shop) {
return (
<Layout shop={shop}>
<ProductGridEmptyMessage
Expand Down Expand Up @@ -159,9 +159,24 @@ class TagGridPage extends Component {
* @returns {Object} props
*/
export async function getStaticProps({ params: { lang, slug } }) {
const primaryShop = await fetchPrimaryShop(lang);

if (!primaryShop) {
return {
props: {
shop: null,
translations: null,
fetchAllTags: null,
tag: null
},
// eslint-disable-next-line camelcase
unstable_revalidate: 1 // Revalidate immediately
};
}

return {
props: {
...await fetchPrimaryShop(lang),
...primaryShop,
...await fetchTranslations(lang, ["common"]),
...await fetchAllTags(lang),
...await fetchTag(slug, lang)
Expand Down
8 changes: 4 additions & 4 deletions staticUtils/graphQLRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import appConfig from "../config";
export default async function graphQLRequest(query, variables) {
const endpoint = appConfig.IS_BUILDING_NEXTJS === true ? appConfig.BUILD_GRAPHQL_URL : appConfig.INTERNAL_GRAPHQL_URL;

const graphQLClient = new GraphQLClient(endpoint, {
timeout: 20000
});

try {
const graphQLClient = new GraphQLClient(endpoint, {
timeout: 20000
});

const data = await graphQLClient.request(query, variables);
return data;
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion staticUtils/shop/fetchPrimaryShop.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import primaryShopQuery from "./primaryShop.js";
export default async function fetchPrimaryShop(language) {
const data = await graphQLRequest(primaryShopQuery, { language });

return data && data.primaryShop && { shop: data.primaryShop };
return (data && data.primaryShop && { shop: data.primaryShop }) || { shop: null };
}