diff --git a/.env.test b/.env.test index 39c0a764..0f034e22 100644 --- a/.env.test +++ b/.env.test @@ -10,5 +10,3 @@ UNILOGIN_SESSION_SECRET=XXX NEXT_PUBLIC_APP_URL=https://hellboy.the-movie.com UNILOGIN_WELLKNOWN_URL=https://hi-i-am-well-known-url.com - -LAGOON_AUTOGENERATED_ROUTES=https://nginx.acme.com,https://node.acme.com,https://varnish.acme.com diff --git a/__tests__/config.test.ts b/__tests__/config.test.ts index b3aae207..cfc26abe 100644 --- a/__tests__/config.test.ts +++ b/__tests__/config.test.ts @@ -12,7 +12,7 @@ describe("Config test suite", () => { expect(() => goConfig("unknown.thingy")).toThrowError(MissingConfigurationError) }) - test("That the env variable NEXT_PUBLIC_APP_URL has precedence over LAGOON_AUTOGENERATED_ROUTES", async () => { + test("That the env variable NEXT_PUBLIC_APP_URL defines the current app url", async () => { const appUrl = goConfig("app.url") expect(appUrl).toBe("https://hellboy.the-movie.com") }) diff --git a/__tests__/dpl-cms.graphql.test.ts b/__tests__/dpl-cms.graphql.test.ts deleted file mode 100644 index 64483f4d..00000000 --- a/__tests__/dpl-cms.graphql.test.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { describe } from "node:test" -import { expect, test } from "vitest" - -import { getDplCmsGraphqlEndpoint } from "@/lib/helpers/dpl-cms.graphql" - -describe("Dpl CMS graphql test suite", () => { - test("That we can resolve the Dpl CMS endpoint graphql URL if the Lagoon Autogenerated Routes are set", async () => { - const url = getDplCmsGraphqlEndpoint() - expect(url).toBe("https://varnish.acme.com/graphql") - }) -}) diff --git a/__tests__/lagoon.test.ts b/__tests__/lagoon.test.ts deleted file mode 100644 index 73535d5c..00000000 --- a/__tests__/lagoon.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { describe } from "node:test" -import { expect, test } from "vitest" - -import { getLagoonUrl } from "@/lib/helpers/lagoon" - -describe("Lagoon test suite", () => { - test("That we can get the node url from Lagoon", async () => { - const url = getLagoonUrl("node") - expect(url).toBe("https://node.acme.com") - }) - - test("That we can get the varnish url from Lagoon", async () => { - const url = getLagoonUrl("varnish") - expect(url).toBe("https://varnish.acme.com") - }) - - test("That we get undefined if the asked url type does NOT exist", async () => { - // @ts-ignore - const url = getLagoonUrl("hannibal") - expect(url).toBeUndefined() - }) -}) diff --git a/lagoon/start.sh b/lagoon/start.sh index f9e42baf..c510ab07 100755 --- a/lagoon/start.sh +++ b/lagoon/start.sh @@ -1,15 +1,38 @@ -#!/bin/sh +getLagoonUrl() { + local type=$1 -# if [ $LAGOON_ENVIRONMENT_TYPE == "production" ]; then -# cd /app -# npm run start -# else -# cd /app -# npm run dev -# fi + for route in ${LAGOON_ROUTES//,/ }; do + if echo "$route" | grep -q "$type"; then + echo "$route" + return + fi + done +} -cd /app +# Make sure app.url is set in application +app_url=$(getLagoonUrl node) +if [ -z "$app_url" ]; then + echo "Error: Unable to determine app URL" + exit 1 +fi + +# Make sure the DPL CMS graphql schema endpoint is set in application +cms_url=$(getLagoonUrl nginx) + +echo "!! cms url: $cms_url" +if [ -z "$cms_url" ]; then + echo "Error: Unable to determine CMS URL" + exit 1 +fi + +# Set the environment variables. +# These ones are varying from environment to environment. +export NEXT_PUBLIC_APP_URL="$app_url" +export NEXT_PUBLIC_GRAPHQL_SCHEMA_ENDPOINT_DPL_CMS="$cms_url/graphql" + +# Go to the app directory if it doesn't exist then never mind. +cd /app || exit 1 # TODO: Remember to adjust the following line before deploying to production. # Using `yarn start:with-server-source-maps` is probably adding a performance overhead. yarn build && yarn start:with-server-source-maps -exit 0; +exit 0 diff --git a/lib/config/resolvers/app.ts b/lib/config/resolvers/app.ts index 6055dafe..0e2b4eb6 100644 --- a/lib/config/resolvers/app.ts +++ b/lib/config/resolvers/app.ts @@ -1,13 +1,8 @@ -import { getLagoonUrl } from "@/lib/helpers/lagoon" - const app = { "app.url": () => { if (process.env.NEXT_PUBLIC_APP_URL) { return process.env.NEXT_PUBLIC_APP_URL } - if (process.env.LAGOON_AUTOGENERATED_ROUTES) { - return getLagoonUrl("node") - } }, } diff --git a/lib/graphql/fetchers/dpl-cms.fetcher.ts b/lib/graphql/fetchers/dpl-cms.fetcher.ts index ff105a39..cfc4df4f 100644 --- a/lib/graphql/fetchers/dpl-cms.fetcher.ts +++ b/lib/graphql/fetchers/dpl-cms.fetcher.ts @@ -1,11 +1,9 @@ -import { getDplCmsGraphqlEndpoint } from "@/lib/helpers/dpl-cms.graphql" - export function fetcher( query: string, variables?: TVariables, options?: RequestInit["headers"] ) { - const dplCmsGraphqlEndpoint = getDplCmsGraphqlEndpoint() + const dplCmsGraphqlEndpoint = process.env.NEXT_PUBLIC_GRAPHQL_SCHEMA_ENDPOINT_DPL_CMS const dplCmsGraphqlBasicToken = process.env.NEXT_PUBLIC_GRAPHQL_BASIC_TOKEN_DPL_CMS if (!dplCmsGraphqlEndpoint || !dplCmsGraphqlBasicToken) { diff --git a/lib/helpers/dpl-cms.graphql.ts b/lib/helpers/dpl-cms.graphql.ts deleted file mode 100644 index 3060e978..00000000 --- a/lib/helpers/dpl-cms.graphql.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { getLagoonUrl } from "./lagoon" - -export const getDplCmsGraphqlEndpoint = () => { - if (process.env.NEXT_PUBLIC_GRAPHQL_SCHEMA_ENDPOINT_DPL_CMS) { - return process.env.NEXT_PUBLIC_GRAPHQL_SCHEMA_ENDPOINT_DPL_CMS - } - - const lagoonUrl = getLagoonUrl("varnish") - if (lagoonUrl) { - return `${lagoonUrl}/graphql` - } -} diff --git a/lib/helpers/lagoon.ts b/lib/helpers/lagoon.ts deleted file mode 100644 index da847a9b..00000000 --- a/lib/helpers/lagoon.ts +++ /dev/null @@ -1,8 +0,0 @@ -export const getLagoonUrl = (type: "nginx" | "varnish" | "node") => { - const routes = process.env.LAGOON_AUTOGENERATED_ROUTES?.split(",") ?? [] - for (const route of routes) { - if (route.includes(type)) { - return route - } - } -}