Skip to content

Commit

Permalink
tro to fix images and env url
Browse files Browse the repository at this point in the history
  • Loading branch information
Magnus Alexander Strømseng committed Apr 10, 2024
1 parent f1fcdd1 commit aff0771
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 36 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/autoredeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ jobs:
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env
echo "TRANSFER_TOKEN_SALT=${{ secrets.TRANSFER_TOKEN_SALT }}" >> .env
# Create .env.production with HOST_URL Frontend
echo "INTERNAL_STRAPI_URL=${{ vars.INTERNAL_STRAPI_URL }}" >> .env.production
echo "OUTSIDE_STRAPI_URL=${{ vars.OUTSIDE_STRAPI_URL }}" >> .env.production
echo "STRAPI_URL=${{ vars.STRAPI_URL }}" >> .env.production
- name: Docker build
run: docker-compose build
- name: Docker up
Expand Down
4 changes: 1 addition & 3 deletions frontend/.env.development
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# Database url for outside requests
OUTSIDE_STRAPI_URL=http://localhost:1337

INTERNAL_STRAPI_URL=http://localhost:1337
STRAPI_URL=http://localhost:1337
4 changes: 1 addition & 3 deletions frontend/.env.production
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Database url for outside requests, set in github repo variables
OUTSIDE_STRAPI_URL=http://web.hypso.ies.ntnu.no:1337
STRAPI_URL=http://web.hypso.ies.ntnu.no:1337

# Database url for internal requests between the docker containers, set in github repo variables
INTERNAL_STRAPI_URL=http://backend:1337
6 changes: 3 additions & 3 deletions frontend/src/app/blog/[articleSlug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BlocksContent } from "@strapi/blocks-react-renderer";
import BlockRendererClient from "@/components/BlockRendererClient";
import { gql } from "@/__generated__/gql";
import { getClient } from "@/lib/ApolloClient";
const OUTSIDE_STRAPI_URL = process.env.OUTSIDE_STRAPI_URL;
const STRAPI_URL = process.env.STRAPI_URL;

const GET_ARTICLE_BY_SLUG = gql(
`query ArticleWithSlug($articlesFilters: ArticleFiltersInput) {
Expand Down Expand Up @@ -70,8 +70,8 @@ export default async function Page({
graphqlData.data.articles?.data[0]?.attributes?.author?.data?.attributes
?.avatar?.data?.attributes?.url;

if (OUTSIDE_STRAPI_URL && avatarURL != undefined) {
avatarURL = OUTSIDE_STRAPI_URL + avatarURL;
if (STRAPI_URL && avatarURL != undefined) {
avatarURL = STRAPI_URL + avatarURL;
}

const article = graphqlData.data.articles?.data[0];
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app/projects/[projectSlug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getClient } from "@/lib/ApolloClient";
import { BlocksContent } from "@strapi/blocks-react-renderer";
import RelatedProjectsAndSatellites from "@/components/RelatedProjectsAndSatellites";
import { ProjectOrSatellite } from "@/app/satellites/[satelliteSlug]/page";
const OUTSIDE_STRAPI_URL = process.env.OUTSIDE_STRAPI_URL;
const STRAPI_URL = process.env.STRAPI_URL;

const GET_PROJECT_BY_SLUG = gql(`
query Projects($projectFilters: ProjectFiltersInput) {
Expand Down Expand Up @@ -69,8 +69,8 @@ export default async function Page({

let projectTitle = projects?.attributes?.slug;

if (OUTSIDE_STRAPI_URL && projectTitle != undefined) {
projectTitle = OUTSIDE_STRAPI_URL + projectTitle;
if (STRAPI_URL && projectTitle != undefined) {
projectTitle = STRAPI_URL + projectTitle;
}
return (
<div className="flex flex-col items-center gap-4">
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app/projects/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
PageSubtitle,
} from "@/components/PageHeader";
import { OuiImage } from "@/components/fullBlogCard";
const OUTSIDE_STRAPI_URL = process.env.OUTSIDE_STRAPI_URL;
const STRAPI_URL = process.env.STRAPI_URL;

const GET_PROJECTS = gql(`
query GET_PROJECTS {
Expand Down Expand Up @@ -71,8 +71,8 @@ export default async function ProjectsPage() {
project?.attributes?.previewImage?.data?.attributes
?.url;

if (OUTSIDE_STRAPI_URL && previewImage != undefined) {
previewImage = OUTSIDE_STRAPI_URL + previewImage;
if (STRAPI_URL && previewImage != undefined) {
previewImage = STRAPI_URL + previewImage;
}
return (
<Link
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app/satellites/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
PageSubtitle,
} from "@/components/PageHeader";

const OUTSIDE_STRAPI_URL = process.env.OUTSIDE_STRAPI_URL;
const STRAPI_URL = process.env.STRAPI_URL;
const GET_SATELLITES = gql(`
query GET_SATELLITES {
satellites {
Expand Down Expand Up @@ -52,11 +52,11 @@ export default async function Satellites() {
satellite?.attributes?.previewImage?.data
?.attributes?.url;
if (
OUTSIDE_STRAPI_URL &&
STRAPI_URL &&
previewImage != undefined
) {
previewImage =
OUTSIDE_STRAPI_URL + previewImage;
STRAPI_URL + previewImage;
}
let satelliteName =
satellite?.attributes?.name ?? "";
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/RelatedProjectsAndSatellites.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ProjectOrSatellite } from "@/app/satellites/[satelliteSlug]/page";
import Link from "next/link";
import Image from "next/image";
const OUTSIDE_STRAPI_URL = process.env.OUTSIDE_STRAPI_URL;
const STRAPI_URL = process.env.STRAPI_URL;
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";

export default function RelatedProjectsAndSatellites({
Expand All @@ -10,8 +10,8 @@ export default function RelatedProjectsAndSatellites({
project: ProjectOrSatellite;
}) {
let previewImage = project.previewImage;
if (OUTSIDE_STRAPI_URL && previewImage != undefined) {
previewImage = OUTSIDE_STRAPI_URL + previewImage;
if (STRAPI_URL && previewImage != undefined) {
previewImage = STRAPI_URL + previewImage;
}
const projectOrSatellite = project.isProject ? "projects" : "satellites";

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/wrappers/ApolloWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import {
SSRMultipartLink,
} from "@apollo/experimental-nextjs-app-support/ssr";

const INTERNAL_STRAPI_URL = process.env.INTERNAL_STRAPI_URL;
const STRAPI_URL = process.env.STRAPI_URL;

// have a function to create a client for you
function makeClient() {
const httpLink = new HttpLink({
// this needs to be an absolute url, as relative urls cannot be used in SSR
uri: INTERNAL_STRAPI_URL + "/graphql",
uri: STRAPI_URL + "/graphql",
// you can disable result caching here if you want to
// (this does not work if you are rendering your page with `export const dynamic = "force-static"`)
fetchOptions: { cache: "no-store" },
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/ApolloClient.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client";
import { registerApolloClient } from "@apollo/experimental-nextjs-app-support/rsc";

const INTERNAL_STRAPI_URL = process.env.INTERNAL_STRAPI_URL;
const STRAPI_URL = process.env.STRAPI_URL;

export const { getClient } = registerApolloClient(() => {
return new ApolloClient({
cache: new InMemoryCache(),
link: new HttpLink({
// this needs to be an absolute url, as relative urls cannot be used in SSR
uri: INTERNAL_STRAPI_URL + "/graphql",
uri: STRAPI_URL + "/graphql",
// you can disable result caching here if you want to
// (this does not work if you are rendering your page with `export const dynamic = "force-static"`)
fetchOptions: { cache: "no-store" },
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/lib/data/fetchArticleInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BlocksContent } from "@strapi/blocks-react-renderer";
import { Enum_Article_Tag } from "@/__generated__/graphql";
import { BlogPost } from "@/app/blog/page";

const OUTSIDE_STRAPI_URL = process.env.OUTSIDE_STRAPI_URL;
const STRAPI_URL = process.env.STRAPI_URL;

const GET_ARTICLES = gql(`
query GET_ARTICLES($pagination: PaginationArg, $filters: ArticleFiltersInput) {
Expand Down Expand Up @@ -106,8 +106,8 @@ export default async function fetchArticlePages({
article?.attributes?.author?.data?.attributes?.avatar?.data
?.attributes?.url;

if (OUTSIDE_STRAPI_URL && avatarURL != undefined) {
avatarURL = OUTSIDE_STRAPI_URL + avatarURL;
if (STRAPI_URL && avatarURL != undefined) {
avatarURL = STRAPI_URL + avatarURL;
}

const authorName: string | undefined =
Expand All @@ -117,8 +117,8 @@ export default async function fetchArticlePages({
const datePublished: any = article?.attributes?.datePublished;
let coverImage: string | undefined =
article?.attributes?.coverImage?.data?.attributes?.url;
if (OUTSIDE_STRAPI_URL && coverImage != undefined) {
coverImage = OUTSIDE_STRAPI_URL + coverImage;
if (STRAPI_URL && coverImage != undefined) {
coverImage = STRAPI_URL + coverImage;
}
let content: BlocksContent = article?.attributes?.body ?? [];

Expand All @@ -139,7 +139,7 @@ export default async function fetchArticlePages({
coverImage,
datePublished,
tag,
HOST_URL: OUTSIDE_STRAPI_URL,
HOST_URL: STRAPI_URL,
authorName,
avatarURL,
slug: article.attributes.slug,
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/lib/data/fetchMostRecentImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { gql } from "@/__generated__/gql";
import { getClient } from "../ApolloClient";
import Image from "next/image";

const OUTSIDE_STRAPI_URL = process.env.OUTSIDE_STRAPI_URL;
const STRAPI_URL = process.env.STRAPI_URL;

const GET_MOST_RECENT_IMAGE = gql(`
query MostRecentImages {
Expand Down Expand Up @@ -43,8 +43,8 @@ export default async function fetchMostrecentImage() {
graphqlData.data.mostRecentImages?.data[0]?.attributes?.mostRecentImage
?.data?.attributes?.url;

if (OUTSIDE_STRAPI_URL && mostRecentImageURL != undefined) {
mostRecentImageURL = OUTSIDE_STRAPI_URL + mostRecentImageURL;
if (STRAPI_URL && mostRecentImageURL != undefined) {
mostRecentImageURL = STRAPI_URL + mostRecentImageURL;
} else {
mostRecentImageURL = "";
}
Expand Down

0 comments on commit aff0771

Please sign in to comment.