Skip to content

Commit

Permalink
Move the Lagoon url resolving to the application build step
Browse files Browse the repository at this point in the history
Because the LAGOON_ROUTES env variable is not accesible client side, we
do the url processing before the build step and turn them into
NEXT_PUBLIC_ variables.
  • Loading branch information
spaceo committed Dec 6, 2024
1 parent 9951c2e commit 3ac62e2
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 74 deletions.
2 changes: 0 additions & 2 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion __tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
Expand Down
11 changes: 0 additions & 11 deletions __tests__/dpl-cms.graphql.test.ts

This file was deleted.

22 changes: 0 additions & 22 deletions __tests__/lagoon.test.ts

This file was deleted.

43 changes: 33 additions & 10 deletions lagoon/start.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 0 additions & 5 deletions lib/config/resolvers/app.ts
Original file line number Diff line number Diff line change
@@ -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")
}
},
}

Expand Down
4 changes: 1 addition & 3 deletions lib/graphql/fetchers/dpl-cms.fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { getDplCmsGraphqlEndpoint } from "@/lib/helpers/dpl-cms.graphql"

export function fetcher<TData, TVariables>(
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) {
Expand Down
12 changes: 0 additions & 12 deletions lib/helpers/dpl-cms.graphql.ts

This file was deleted.

8 changes: 0 additions & 8 deletions lib/helpers/lagoon.ts

This file was deleted.

0 comments on commit 3ac62e2

Please sign in to comment.