Skip to content

Commit

Permalink
Try to fix production problems
Browse files Browse the repository at this point in the history
  • Loading branch information
deeprobin committed Aug 6, 2023
1 parent 7c432a0 commit eb0cb5c
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 9 deletions.
File renamed without changes
Binary file added src/assets/communication.webp
Binary file not shown.
Binary file added src/assets/hero.webp
Binary file not shown.
Binary file added src/assets/lindner.webp
Binary file not shown.
2 changes: 1 addition & 1 deletion src/components/Hero.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import { getImage } from "astro:assets";
import hero from "~/assets/hero.jpg";
import hero from "../assets/hero.webp";
import { Button } from "./Button/Button";
import { useTranslations } from "../i18n";
const optimizedHero = await getImage({
Expand Down
27 changes: 23 additions & 4 deletions src/contentful.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,31 @@ if (process.env.CONTENTFUL_SPACE_ID === undefined) {
console.error("CONTENTFUL_SPACE_ID is undefined. This will produce undefined behavior!");
throw new Error("CONTENTFUL_SPACE_ID is undefined.");
}

let contentfulToken: string | undefined;
let contentfulHost: string = "cdn.contentful.com";
if (process.env.NODE_ENV?.toLowerCase() !== "production") {
contentfulHost = "preview.contentful.com";
contentfulToken = process.env.CONTENTFUL_PREVIEW_TOKEN;
console.log(`Contentful environment: Preview (${contentfulHost})`)
if (contentfulToken === undefined) {
console.error("CONTENTFUL_PREVIEW_TOKEN is undefined.");
throw new Error("CONTENTFUL_PREVIEW_TOKEN is undefined.");
}
}
else {
contentfulToken = process.env.CONTENTFUL_DELIVERY_TOKEN;
console.log(`Contentful environment: Production (${contentfulHost})`)
if (contentfulToken === undefined) {
console.error("CONTENTFUL_DELIVERY_TOKEN is undefined.");
throw new Error("CONTENTFUL_DELIVERY_TOKEN is undefined.");
}
}

// Do not use import.meta.env because import.meta.envs are replaced in build-time
// Secrets should be runtime-only
export const contentfulClient = contentful.createClient({
space: process.env.CONTENTFUL_SPACE_ID!,
accessToken: process.env.DEV
? process.env.CONTENTFUL_PREVIEW_TOKEN!
: process.env.CONTENTFUL_DELIVERY_TOKEN!,
host: process.env.DEV ? "preview.contentful.com" : "cdn.contentful.com",
accessToken: contentfulToken,
host: contentfulHost,
});
2 changes: 1 addition & 1 deletion src/pages/[language]/about-us.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Footer from "../../components/Footer.astro";
import Header from "../../components/Header.astro";
import Heading from "../../components/Heading.astro";
import BaseLayout from "../../layouts/BaseLayout.astro";
import lindner from "~/assets/lindner.jpg";
import lindner from "../../assets/lindner.webp";
import { Image } from "astro:assets";
import { Button } from "../../components/Button/Button";
import HookSection from "../../components/HookSection.astro";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/[language]/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import HookSection from "../../components/HookSection.astro";
import BaseLayout from "../../layouts/BaseLayout.astro";
import { Image } from "astro:assets";
import aboutUsImage from "~/assets/shutterstock_792913780_cropped.jpg";
import aboutUsImage from "../../assets/communication.webp";
import Footer from "../../components/Footer.astro";
import { useTranslations } from "../../i18n";
import { MetaBuilder } from "../../meta";
Expand Down
4 changes: 2 additions & 2 deletions src/pages/cms-assets/[asset]/[uid]/[image].ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export const get: APIRoute = async function get({ params, request }) {
let requestUrl = new URL(`https://images.ctfassets.net/${contentfulSpaceId}/${asset}/${uid}/${image}`);
requestUrl.searchParams.set("fm", format);
if (width) {
requestUrl.searchParams.set("width", width);
requestUrl.searchParams.set("w", width);
}
if (height) {
requestUrl.searchParams.set("height", height);
requestUrl.searchParams.set("h", height);
}
const response = await fetch(requestUrl, {
headers: {
Expand Down

0 comments on commit eb0cb5c

Please sign in to comment.