Maybe finally fix public env vars

This commit is contained in:
Liam 2022-10-26 17:13:30 +01:00
parent 6935e411b7
commit 725aff67cb
11 changed files with 104 additions and 76 deletions

12
.env Normal file

@ -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

@ -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 REACT_APP_SITE_NAME=BeatSaber Overlay
NEXT_PUBLIC_SITE_TITLE=BeatSaber Overlay - Simple and easy to use BeatSaber overlay REACT_APP_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 REACT_APP_SITE_DESCRIPTION=Free, simple, and easy to use beat saber overlay for OBS
NEXT_PUBLIC_SITE_COLOR=0EBFE9 REACT_APP_SITE_COLOR=0EBFE9
NEXT_PUBLIC_SITE_URL=https://bs-overlay.fascinated.cc REACT_APP_SITE_URL=https://bs-overlay.fascinated.cc
REDIS_PORT=6379 REDIS_PORT=6379
REDIS_HOST=127.0.0.1 REDIS_HOST=127.0.0.1

@ -25,16 +25,7 @@ COPY . .
# Uncomment the following line in case you want to disable telemetry during the build. # Uncomment the following line in case you want to disable telemetry during the build.
ENV NEXT_TELEMETRY_DISABLED 1 ENV NEXT_TELEMETRY_DISABLED 1
RUN yarn build
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
# If using npm comment out above and use below instead # If using npm comment out above and use below instead
# RUN npm run build # 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/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/public ./.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 RUN chown -R nextjs:nodejs /app
USER nextjs USER nextjs
@ -70,5 +58,5 @@ EXPOSE 3000
ENV PORT 3000 ENV PORT 3000
ENTRYPOINT ["/app/entrypoint.sh"] ENTRYPOINT yarn react-env --env APP_ENV
CMD ["node", "server.js"] CMD ["node", "server.js"]

@ -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 "$@"

@ -2,12 +2,13 @@
"name": "beatsaber-overlay", "name": "beatsaber-overlay",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "set APP_ENV=development && next dev", "dev": "react-env -- next",
"build": "next build", "build": "next build",
"start": "APP_ENV=production next start -p 3001", "start": "APP_ENV=production next start -p 3001",
"lint": "next lint" "lint": "next lint"
}, },
"dependencies": { "dependencies": {
"@beam-australia/react-env": "^3.1.1",
"@emotion/cache": "^11.10.3", "@emotion/cache": "^11.10.3",
"@emotion/server": "^11.10.0", "@emotion/server": "^11.10.0",
"@nextui-org/react": "^1.0.0-beta.10", "@nextui-org/react": "^1.0.0-beta.10",

1
public/__ENV.js Normal file

@ -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"};

@ -1,9 +1,10 @@
import env from "@beam-australia/react-env";
const WebsiteTypes = { const WebsiteTypes = {
ScoreSaber: { ScoreSaber: {
ApiUrl: { ApiUrl: {
PlayerData: PlayerData:
process.env.NEXT_PUBLIC_HTTP_PROXY + env("HTTP_PROXY") + "/https://scoresaber.com/api/player/%s/basic",
"/https://scoresaber.com/api/player/%s/basic",
MapData: MapData:
"https://scoresaber.com/api/leaderboard/by-hash/%h/info?difficulty=%d", "https://scoresaber.com/api/leaderboard/by-hash/%h/info?difficulty=%d",
}, },
@ -17,9 +18,7 @@ const WebsiteTypes = {
}, },
BeatLeader: { BeatLeader: {
ApiUrl: { ApiUrl: {
PlayerData: PlayerData: env("HTTP_PROXY") + "/https://api.beatleader.xyz/player/%s",
process.env.NEXT_PUBLIC_HTTP_PROXY +
"/https://api.beatleader.xyz/player/%s",
MapData: "https://api.beatleader.xyz/map/hash/%h", MapData: "https://api.beatleader.xyz/map/hash/%h",
}, },
async getMapStarCount(mapHash, mapDiff, characteristic) { async getMapStarCount(mapHash, mapDiff, characteristic) {

@ -1,9 +1,9 @@
import env from "@beam-australia/react-env";
import { BeatSaverMapData } from "../types/BeatSaverMapData"; import { BeatSaverMapData } from "../types/BeatSaverMapData";
import { getValue, setValue, valueExists } from "../utils/redisUtils"; import { getValue, setValue, valueExists } from "../utils/redisUtils";
const BEATSAVER_MAP_API = const BEATSAVER_MAP_API =
process.env.NEXT_PUBLIC_HTTP_PROXY + env("HTTP_PROXY") + "/https://api.beatsaver.com/maps/hash/%s";
"/https://api.beatsaver.com/maps/hash/%s";
const KEY = "BS_MAP_DATA_"; const KEY = "BS_MAP_DATA_";

@ -1,3 +1,4 @@
import env from "@beam-australia/react-env";
import { createTheme, NextUIProvider } from "@nextui-org/react"; import { createTheme, NextUIProvider } from "@nextui-org/react";
import { DefaultSeo } from "next-seo"; import { DefaultSeo } from "next-seo";
import { ThemeProvider as NextThemesProvider } from "next-themes"; import { ThemeProvider as NextThemesProvider } from "next-themes";
@ -21,13 +22,13 @@ function MyApp({ Component, pageProps }) {
return ( return (
<> <>
<DefaultSeo <DefaultSeo
titleTemplate={`${process.env.NEXT_PUBLIC_SITE_NAME} | %s`} titleTemplate={`${env("SITE_NAME")} | %s`}
description={process.env.NEXT_PUBLIC_SITE_DESCRIPTION} description={env("SITE_DESCRIPTION}")}
openGraph={{ openGraph={{
url: process.env.NEXT_PUBLIC_SITE_URL, url: env("SITE_URL"),
title: process.env.NEXT_PUBLIC_SITE_NAME, title: env("SITE_NAME"),
description: process.env.NEXT_PUBLIC_SITE_DESCRIPTION, description: env("SITE_DESCRIPTION"),
site_name: process.env.NEXT_PUBLIC_SITE_NAME, site_name: env("SITE_NAME"),
images: [ images: [
{ {
url: "https://cdn.fascinated.cc/fHknFPctAC.png?raw=true", url: "https://cdn.fascinated.cc/fHknFPctAC.png?raw=true",

@ -1,3 +1,4 @@
import env from "@beam-australia/react-env";
import { CssBaseline, Image } from "@nextui-org/react"; import { CssBaseline, Image } from "@nextui-org/react";
import Document, { Head, Html, Main, NextScript } from "next/document"; import Document, { Head, Html, Main, NextScript } from "next/document";
import React from "react"; import React from "react";
@ -15,6 +16,7 @@ class MyDocument extends Document {
return ( return (
<Html lang="en"> <Html lang="en">
<Head> <Head>
<script defer src="/__ENV.js" />
{CssBaseline.flush()} {CssBaseline.flush()}
<link <link
@ -27,10 +29,7 @@ class MyDocument extends Document {
/> />
<link rel="shortcut icon" href="/favicon.ico" /> <link rel="shortcut icon" href="/favicon.ico" />
<meta <meta name="theme-color" content={"#" + env("SITE_COLOR")} />
name="theme-color"
content={"#" + process.env.NEXT_PUBLIC_SITE_COLOR}
/>
<meta <meta
property="og:keywords" property="og:keywords"
content="BeatSaber,Overlay,OBS,Twitch,YouTube,BeatSaber Overlay,Github," content="BeatSaber,Overlay,OBS,Twitch,YouTube,BeatSaber Overlay,Github,"

@ -17,6 +17,16 @@
dependencies: dependencies:
regenerator-runtime "^0.13.4" regenerator-runtime "^0.13.4"
"@beam-australia/react-env@^3.1.1":
version "3.1.1"
resolved "https://registry.yarnpkg.com/@beam-australia/react-env/-/react-env-3.1.1.tgz#63cb8316861b8fbdb4b9c550a62139cd90675e40"
integrity sha512-LdWzgqmu116t9+sOvONyB21bBmI8dm8g8s3KhnJVzCcK93GrdSisuIOtOkQPMYgenmVGTWQwWnbLAgoka/jAFw==
dependencies:
cross-spawn "^6.0.5"
dotenv "^8.0.0"
dotenv-expand "^5.1.0"
minimist "^1.2.0"
"@emotion/cache@^11.10.3": "@emotion/cache@^11.10.3":
version "11.10.3" version "11.10.3"
resolved "https://registry.npmjs.org/@emotion/cache/-/cache-11.10.3.tgz" resolved "https://registry.npmjs.org/@emotion/cache/-/cache-11.10.3.tgz"
@ -1247,6 +1257,17 @@ critters@^0.0.16:
postcss "^8.3.7" postcss "^8.3.7"
pretty-bytes "^5.3.0" pretty-bytes "^5.3.0"
cross-spawn@^6.0.5:
version "6.0.5"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==
dependencies:
nice-try "^1.0.4"
path-key "^2.0.1"
semver "^5.5.0"
shebang-command "^1.2.0"
which "^1.2.9"
cross-spawn@^7.0.2: cross-spawn@^7.0.2:
version "7.0.3" version "7.0.3"
resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz" resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz"
@ -1394,6 +1415,16 @@ domutils@^2.8.0:
domelementtype "^2.2.0" domelementtype "^2.2.0"
domhandler "^4.2.0" domhandler "^4.2.0"
dotenv-expand@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-5.1.0.tgz#3fbaf020bfd794884072ea26b1e9791d45a629f0"
integrity sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA==
dotenv@^8.0.0:
version "8.6.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.6.0.tgz#061af664d19f7f4d8fc6e4ff9b584ce237adcb8b"
integrity sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==
duplexer2@^0.1.2: duplexer2@^0.1.2:
version "0.1.4" version "0.1.4"
resolved "https://registry.npmjs.org/duplexer2/-/duplexer2-0.1.4.tgz" resolved "https://registry.npmjs.org/duplexer2/-/duplexer2-0.1.4.tgz"
@ -2325,6 +2356,11 @@ next@12:
"@next/swc-win32-ia32-msvc" "12.3.1" "@next/swc-win32-ia32-msvc" "12.3.1"
"@next/swc-win32-x64-msvc" "12.3.1" "@next/swc-win32-x64-msvc" "12.3.1"
nice-try@^1.0.4:
version "1.0.5"
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==
node-abi@^3.3.0: node-abi@^3.3.0:
version "3.28.0" version "3.28.0"
resolved "https://registry.npmjs.org/node-abi/-/node-abi-3.28.0.tgz" resolved "https://registry.npmjs.org/node-abi/-/node-abi-3.28.0.tgz"
@ -2485,6 +2521,11 @@ path-is-absolute@^1.0.0:
resolved "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz" resolved "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz"
integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18= integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=
path-key@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40"
integrity sha512-fEHGKCSmUSDPv4uoj8AlD+joPlq3peND+HRYyxFz4KPw4z926S/b8rIuFs2FYJg3BwsxJf6A9/3eIdLaYC+9Dw==
path-key@^3.1.0: path-key@^3.1.0:
version "3.1.1" version "3.1.1"
resolved "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz" resolved "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz"
@ -2761,6 +2802,11 @@ scheduler@^0.23.0:
dependencies: dependencies:
loose-envify "^1.1.0" loose-envify "^1.1.0"
semver@^5.5.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==
semver@^6.3.0: semver@^6.3.0:
version "6.3.0" version "6.3.0"
resolved "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz" resolved "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz"
@ -2787,6 +2833,13 @@ sharp@^0.31.1:
tar-fs "^2.1.1" tar-fs "^2.1.1"
tunnel-agent "^0.6.0" tunnel-agent "^0.6.0"
shebang-command@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea"
integrity sha512-EV3L1+UQWGor21OmnvojK36mhg+TyIKDh3iFBKBohr5xeXIhNBcx8oWdgkTEEQ+BEFFYdLRuqMfd5L84N1V5Vg==
dependencies:
shebang-regex "^1.0.0"
shebang-command@^2.0.0: shebang-command@^2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz" resolved "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz"
@ -2794,6 +2847,11 @@ shebang-command@^2.0.0:
dependencies: dependencies:
shebang-regex "^3.0.0" shebang-regex "^3.0.0"
shebang-regex@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
integrity sha512-wpoSFAxys6b2a2wHZ1XpDSgD7N9iVjg29Ph9uV/uaP9Ex/KXlkTZTeddxDPSYQpgvzKLGJke2UU0AzoGCjNIvQ==
shebang-regex@^3.0.0: shebang-regex@^3.0.0:
version "3.0.0" version "3.0.0"
resolved "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz" resolved "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz"
@ -3079,6 +3137,13 @@ which-boxed-primitive@^1.0.2:
is-string "^1.0.5" is-string "^1.0.5"
is-symbol "^1.0.3" is-symbol "^1.0.3"
which@^1.2.9:
version "1.3.1"
resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"
integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==
dependencies:
isexe "^2.0.0"
which@^2.0.1: which@^2.0.1:
version "2.0.2" version "2.0.2"
resolved "https://registry.npmjs.org/which/-/which-2.0.2.tgz" resolved "https://registry.npmjs.org/which/-/which-2.0.2.tgz"