From 725aff67cb510241cde6188c532e4ba4a46fc78a Mon Sep 17 00:00:00 2001 From: Liam <67254223+RealFascinated@users.noreply.github.com> Date: Wed, 26 Oct 2022 17:13:30 +0100 Subject: [PATCH] Maybe finally fix public env vars --- .env | 12 ++++++ .env.local-example | 12 +++--- Dockerfile | 16 +------- entrypoint.sh | 38 ------------------- package.json | 3 +- public/__ENV.js | 1 + src/consts/LeaderboardType.js | 9 ++--- src/helpers/beatSaverHelpers.ts | 4 +- src/pages/_app.js | 13 ++++--- src/pages/_document.js | 7 ++-- yarn.lock | 65 +++++++++++++++++++++++++++++++++ 11 files changed, 104 insertions(+), 76 deletions(-) create mode 100644 .env delete mode 100644 entrypoint.sh create mode 100644 public/__ENV.js diff --git a/.env b/.env new file mode 100644 index 0000000..a790d5b --- /dev/null +++ b/.env @@ -0,0 +1,12 @@ +REACT_APP_HTTP_PROXY=https://proxy.fascinated.cc + +REACT_APP_SITE_NAME=BeatSaber Overlay +REACT_APP_SITE_TITLE=BeatSaber Overlay - Simple and easy to use BeatSaber overlay +REACT_APP_SITE_DESCRIPTION=Free, simple, and easy to use beat saber overlay for OBS +REACT_APP_SITE_COLOR=0EBFE9 +REACT_APP_SITE_URL=https://bs-overlay.fascinated.cc + +REDIS_PORT=6379 +REDIS_HOST=195.154.220.97 +REDIS_PASSWORD=zgrq2L7TmhRLvwrBcosaSLi3pMjq6x7Arz4W2M3zDHt4 +REDIS_DATABASE=0 \ No newline at end of file diff --git a/.env.local-example b/.env.local-example index 8f671bf..e1e1c8a 100644 --- a/.env.local-example +++ b/.env.local-example @@ -1,10 +1,10 @@ -NEXT_PUBLIC_HTTP_PROXY=https://proxy.fascinated.cc +REACT_APP_HTTP_PROXY=https://proxy.fascinated.cc -NEXT_PUBLIC_SITE_NAME=BeatSaber Overlay -NEXT_PUBLIC_SITE_TITLE=BeatSaber Overlay - Simple and easy to use BeatSaber overlay -NEXT_PUBLIC_SITE_DESCRIPTION=Free, simple, and easy to use beat saber overlay for OBS -NEXT_PUBLIC_SITE_COLOR=0EBFE9 -NEXT_PUBLIC_SITE_URL=https://bs-overlay.fascinated.cc +REACT_APP_SITE_NAME=BeatSaber Overlay +REACT_APP_SITE_TITLE=BeatSaber Overlay - Simple and easy to use BeatSaber overlay +REACT_APP_SITE_DESCRIPTION=Free, simple, and easy to use beat saber overlay for OBS +REACT_APP_SITE_COLOR=0EBFE9 +REACT_APP_SITE_URL=https://bs-overlay.fascinated.cc REDIS_PORT=6379 REDIS_HOST=127.0.0.1 diff --git a/Dockerfile b/Dockerfile index 282521e..f75e7be 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,16 +25,7 @@ COPY . . # Uncomment the following line in case you want to disable telemetry during the build. ENV NEXT_TELEMETRY_DISABLED 1 - -RUN \ - NEXT_PUBLIC_HTTP_PROXY=APP_NEXT_PUBLIC_HTTP_PROXY \ - NEXT_PUBLIC_SITE_NAME=APP_NEXT_PUBLIC_SITE_NAME \ - NEXT_PUBLIC_SITE_TITLE=APP_NEXT_PUBLIC_SITE_TITLE \ - NEXT_PUBLIC_SITE_DESCRIPTION=APP_NEXT_PUBLIC_SITE_DESCRIPTION \ - NEXT_PUBLIC_SITE_COLOR=APP_NEXT_NEXT_PUBLIC_SITE_COLOR \ - NEXT_PUBLIC_SITE_URL=APP_NEXT_PUBLIC_SITE_URL \ - yarn build - +RUN yarn build # If using npm comment out above and use below instead # RUN npm run build @@ -59,9 +50,6 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static COPY --from=builder --chown=nextjs:nodejs /app/public ./.next/static -COPY --from=builder --chown=nextjs:nodejs /app/entrypoint.sh ./entrypoint.sh -RUN chmod 777 /app/entrypoint.sh - RUN chown -R nextjs:nodejs /app USER nextjs @@ -70,5 +58,5 @@ EXPOSE 3000 ENV PORT 3000 -ENTRYPOINT ["/app/entrypoint.sh"] +ENTRYPOINT yarn react-env --env APP_ENV CMD ["node", "server.js"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100644 index d5369b7..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh - -echo "Checking that NEXT_PUBLIC_API_URL env-var exists" -test -n "$NEXT_PUBLIC_HTTP_PROXY" -echo "Found $NEXT_PUBLIC_HTTP_PROXY" - -echo "Checking that NEXT_PUBLIC_SITE_NAME env-var exists" -test -n "$NEXT_PUBLIC_SITE_NAME" -echo "Found $NEXT_PUBLIC_SITE_NAME" - -echo "Checking that NEXT_PUBLIC_SITE_TITLE env-var exists" -test -n "$NEXT_PUBLIC_SITE_TITLE" -echo "Found $NEXT_PUBLIC_SITE_TITLE" - -echo "Checking that NEXT_PUBLIC_SITE_DESCRIPTION env-var exists" -test -n "$NEXT_PUBLIC_SITE_DESCRIPTION" -echo "Found $NEXT_PUBLIC_SITE_DESCRIPTION" - -echo "Checking that NEXT_PUBLIC_SITE_COLOR env-var exists" -test -n "$NEXT_PUBLIC_SITE_COLOR" -echo "Found $NEXT_PUBLIC_SITE_COLOR" - -echo "Checking that NEXT_PUBLIC_SITE_URL env-var exists" -test -n "$NEXT_PUBLIC_SITE_URL" -echo "Found $NEXT_PUBLIC_SITE_COLOR" - -echo "Ignore permission errors below" - -find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#APP_NEXT_PUBLIC_HTTP_PROXY#$NEXT_PUBLIC_HTTP_PROXY#g" -find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#APP_NEXT_PUBLIC_SITE_NAME#$NEXT_PUBLIC_SITE_NAME#g" -find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#APP_NEXT_PUBLIC_SITE_TITLE#$NEXT_PUBLIC_SITE_TITLE#g" -find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#APP_NEXT_PUBLIC_SITE_DESCRIPTION#$NEXT_PUBLIC_SITE_DESCRIPTION#g" -find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#APP_NEXT_PUBLIC_SITE_COLOR#$NEXT_PUBLIC_SITE_COLOR#g" -find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#APP_NEXT_PUBLIC_SITE_URL#$NEXT_PUBLIC_SITE_URL#g" - -echo "Starting NextJS" -exec "$@" - \ No newline at end of file diff --git a/package.json b/package.json index 37762bc..c9bc2f1 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,13 @@ "name": "beatsaber-overlay", "private": true, "scripts": { - "dev": "set APP_ENV=development && next dev", + "dev": "react-env -- next", "build": "next build", "start": "APP_ENV=production next start -p 3001", "lint": "next lint" }, "dependencies": { + "@beam-australia/react-env": "^3.1.1", "@emotion/cache": "^11.10.3", "@emotion/server": "^11.10.0", "@nextui-org/react": "^1.0.0-beta.10", diff --git a/public/__ENV.js b/public/__ENV.js new file mode 100644 index 0000000..c2b8f23 --- /dev/null +++ b/public/__ENV.js @@ -0,0 +1 @@ +window.__ENV = {"REACT_APP_HTTP_PROXY":"https://proxy.fascinated.cc","REACT_APP_SITE_COLOR":"0EBFE9","REACT_APP_SITE_DESCRIPTION":"Free, simple, and easy to use beat saber overlay for OBS","REACT_APP_SITE_NAME":"BeatSaber Overlay","REACT_APP_SITE_TITLE":"BeatSaber Overlay - Simple and easy to use BeatSaber overlay","REACT_APP_SITE_URL":"https://bs-overlay.fascinated.cc"}; \ No newline at end of file diff --git a/src/consts/LeaderboardType.js b/src/consts/LeaderboardType.js index 3967fe4..f71ed4d 100644 --- a/src/consts/LeaderboardType.js +++ b/src/consts/LeaderboardType.js @@ -1,9 +1,10 @@ +import env from "@beam-australia/react-env"; + const WebsiteTypes = { ScoreSaber: { ApiUrl: { PlayerData: - process.env.NEXT_PUBLIC_HTTP_PROXY + - "/https://scoresaber.com/api/player/%s/basic", + env("HTTP_PROXY") + "/https://scoresaber.com/api/player/%s/basic", MapData: "https://scoresaber.com/api/leaderboard/by-hash/%h/info?difficulty=%d", }, @@ -17,9 +18,7 @@ const WebsiteTypes = { }, BeatLeader: { ApiUrl: { - PlayerData: - process.env.NEXT_PUBLIC_HTTP_PROXY + - "/https://api.beatleader.xyz/player/%s", + PlayerData: env("HTTP_PROXY") + "/https://api.beatleader.xyz/player/%s", MapData: "https://api.beatleader.xyz/map/hash/%h", }, async getMapStarCount(mapHash, mapDiff, characteristic) { diff --git a/src/helpers/beatSaverHelpers.ts b/src/helpers/beatSaverHelpers.ts index 113f75b..73f93aa 100644 --- a/src/helpers/beatSaverHelpers.ts +++ b/src/helpers/beatSaverHelpers.ts @@ -1,9 +1,9 @@ +import env from "@beam-australia/react-env"; import { BeatSaverMapData } from "../types/BeatSaverMapData"; import { getValue, setValue, valueExists } from "../utils/redisUtils"; const BEATSAVER_MAP_API = - process.env.NEXT_PUBLIC_HTTP_PROXY + - "/https://api.beatsaver.com/maps/hash/%s"; + env("HTTP_PROXY") + "/https://api.beatsaver.com/maps/hash/%s"; const KEY = "BS_MAP_DATA_"; diff --git a/src/pages/_app.js b/src/pages/_app.js index 3cbe125..6b7124f 100644 --- a/src/pages/_app.js +++ b/src/pages/_app.js @@ -1,3 +1,4 @@ +import env from "@beam-australia/react-env"; import { createTheme, NextUIProvider } from "@nextui-org/react"; import { DefaultSeo } from "next-seo"; import { ThemeProvider as NextThemesProvider } from "next-themes"; @@ -21,13 +22,13 @@ function MyApp({ Component, pageProps }) { return ( <> +