From 9190b9a2a034abfae9fe33516b698ea9dbe3b202 Mon Sep 17 00:00:00 2001 From: Ore Ogundipe Date: Wed, 21 Aug 2024 19:54:32 +0100 Subject: [PATCH] build: load env dynamically for app service instance (#235) * add: env setups * add: load env for serverside runs * fix: dynamic loading of env variables * fix: remove .env.local * edit: foce dummy placeholder * add: force loading from .env * env: remove build secret reference * fix: create .env.prod during build for app service run * fix: remove unecessary * fix: see if adding this mapping fixes it --- .github/workflows/staging_fusion-staging.yml | 3 +++ frontend/.env.local | 1 - frontend/next.config.js | 5 +++++ frontend/src/config/constants.ts | 2 +- frontend/src/pages/analysis.tsx | 2 +- frontend/src/pages/api/auth/[...nextauth].ts | 2 +- frontend/src/pages/sitemap.xml.tsx | 2 +- frontend/src/services/auth.service.ts | 4 ++-- frontend/src/services/storage.service.ts | 2 +- frontend/src/utils/appInsights.ts | 3 ++- frontend/src/utils/azure.ts | 4 ++-- 11 files changed, 19 insertions(+), 11 deletions(-) delete mode 100644 frontend/.env.local diff --git a/.github/workflows/staging_fusion-staging.yml b/.github/workflows/staging_fusion-staging.yml index 1b931b06..ef800c73 100644 --- a/.github/workflows/staging_fusion-staging.yml +++ b/.github/workflows/staging_fusion-staging.yml @@ -28,6 +28,9 @@ jobs: run: | cd frontend npm install + echo "NEXT_PUBLIC_FUSION_RELAY_URL=${{ secrets.NEXT_PUBLIC_FUSION_RELAY_URL }}" >> .env.production + echo "NEXT_PUBLIC_FUSION_NOSTR_PUBLIC_KEY=${{ secrets.NEXT_PUBLIC_FUSION_NOSTR_PUBLIC_KEY }}" >> .env.production + echo "NEXT_PUBLIC_NEUROFUSION_BACKEND_URL=${{ secrets.NEXT_PUBLIC_NEUROFUSION_BACKEND_URL }}" >> .env.production npm run build --if-present npm run test --if-present diff --git a/frontend/.env.local b/frontend/.env.local deleted file mode 100644 index d182595e..00000000 --- a/frontend/.env.local +++ /dev/null @@ -1 +0,0 @@ -NEXT_PUBLIC_APP_INSIGHTS_KEY="5a52ca8a-bd71-4c4c-84f6-d51429acbe03" \ No newline at end of file diff --git a/frontend/next.config.js b/frontend/next.config.js index 75f186b3..ef6ad63d 100644 --- a/frontend/next.config.js +++ b/frontend/next.config.js @@ -9,4 +9,9 @@ module.exports = { }, ]; }, + env: { + NEXT_PUBLIC_FUSION_RELAY_URL: process.env.NEXT_PUBLIC_FUSION_RELAY_URL, + NEXT_PUBLIC_FUSION_NOSTR_PUBLIC_KEY: process.env.NEXT_PUBLIC_FUSION_NOSTR_PUBLIC_KEY, + NEXT_PUBLIC_NEUROFUSION_BACKEND_URL: process.env.NEXT_PUBLIC_NEUROFUSION_BACKEND_URL, + }, }; diff --git a/frontend/src/config/constants.ts b/frontend/src/config/constants.ts index a96b274e..abcdb9c6 100644 --- a/frontend/src/config/constants.ts +++ b/frontend/src/config/constants.ts @@ -1,6 +1,6 @@ import { DefaultOptions } from "@tanstack/react-query"; -export const API_URL = process.env.NEXT_PUBLIC_NEUROFUSION_BACKEND_URL; +export const API_URL = process.env["NEXT_PUBLIC_NEUROFUSION_BACKEND_URL"]; export const QUERY_OPTIONS_DEFAULT: DefaultOptions = { queries: { diff --git a/frontend/src/pages/analysis.tsx b/frontend/src/pages/analysis.tsx index 3d13781e..659dc490 100644 --- a/frontend/src/pages/analysis.tsx +++ b/frontend/src/pages/analysis.tsx @@ -45,7 +45,7 @@ const AnalysisPage: NextPage = () => { try { setLoading(true); - const response = await fetch(`${process.env.NEXT_PUBLIC_ANALYSIS_SERVER_URL}/api/v1/process_eeg`, { + const response = await fetch(`${process.env["NEXT_PUBLIC_ANALYSIS_SERVER_URL"]}/api/v1/process_eeg`, { method: "POST", body: formData, }); diff --git a/frontend/src/pages/api/auth/[...nextauth].ts b/frontend/src/pages/api/auth/[...nextauth].ts index a807b6c6..1010dd82 100644 --- a/frontend/src/pages/api/auth/[...nextauth].ts +++ b/frontend/src/pages/api/auth/[...nextauth].ts @@ -8,7 +8,7 @@ import CredentialsProvider from "next-auth/providers/credentials"; import { randomBytes } from "crypto"; export const authOptions: NextAuthOptions = { - secret: process.env.NEXT_AUTH_SECRET, + secret: process.env["NEXT_AUTH_SECRET"], session: { // Seconds - How long until an idle session expires and is no longer valid. maxAge: 30 * 24 * 60 * 60, // 30 days diff --git a/frontend/src/pages/sitemap.xml.tsx b/frontend/src/pages/sitemap.xml.tsx index d2454838..7abfb6da 100644 --- a/frontend/src/pages/sitemap.xml.tsx +++ b/frontend/src/pages/sitemap.xml.tsx @@ -6,7 +6,7 @@ const Sitemap = () => { }; export const getServerSideProps: GetServerSideProps = async ({ res }) => { - const baseUrl = process.env.NEXTAUTH_URL || "https://usefusion.ai"; + const baseUrl = process.env["NEXTAUTH_URL"] || "https://usefusion.ai"; const blogs = (await getAllPostsWithFrontMatter()).map((post: any) => ({ url: `${baseUrl}/blog/${post.slug}`, diff --git a/frontend/src/services/auth.service.ts b/frontend/src/services/auth.service.ts index 7fb292cf..cd109507 100644 --- a/frontend/src/services/auth.service.ts +++ b/frontend/src/services/auth.service.ts @@ -10,10 +10,10 @@ interface AuthResponse { class AuthService { async completeNostrLogin(publicKey: string, privateKey?: string): Promise { - const serverPublicKey = process.env.NEXT_PUBLIC_FUSION_NOSTR_PUBLIC_KEY; + const serverPublicKey = process.env["NEXT_PUBLIC_FUSION_NOSTR_PUBLIC_KEY"]; try { - const relay = relayInit(process.env.NEXT_PUBLIC_FUSION_RELAY_URL!); + const relay = relayInit(process.env["NEXT_PUBLIC_FUSION_RELAY_URL"]!); relay.on("connect", () => { console.log(`connected to ${relay.url}`); }); diff --git a/frontend/src/services/storage.service.ts b/frontend/src/services/storage.service.ts index d3b46a35..a847a1ea 100644 --- a/frontend/src/services/storage.service.ts +++ b/frontend/src/services/storage.service.ts @@ -35,7 +35,7 @@ export async function writeDataToStore(dataName: string, data: any, fileTimestam } else if (storeType === "remoteStorage") { // call the upload api (async () => { - const res = await axios.post(`${process.env.NEXT_PUBLIC_NEUROFUSION_BACKEND_URL}/api/storage/upload`, { + const res = await axios.post(`${process.env["NEXT_PUBLIC_NEUROFUSION_BACKEND_URL"]}/api/storage/upload`, { provider: providerName, dataName: dataName, // eslint-disable-line object-shorthand fileTimestamp: fileTimestamp, // eslint-disable-line object-shorthand diff --git a/frontend/src/utils/appInsights.ts b/frontend/src/utils/appInsights.ts index fceed9cb..df99588e 100644 --- a/frontend/src/utils/appInsights.ts +++ b/frontend/src/utils/appInsights.ts @@ -6,7 +6,7 @@ const reactPlugin = new ReactPlugin(); const appInsights = new ApplicationInsights({ config: { - instrumentationKey: process.env.NEXT_PUBLIC_APP_INSIGHTS_KEY, + instrumentationKey: process.env["NEXT_PUBLIC_APP_INSIGHTS_KEY"] || "", extensions: [reactPlugin], enableAutoRouteTracking: true, disableAjaxTracking: false, @@ -14,6 +14,7 @@ const appInsights = new ApplicationInsights({ enableCorsCorrelation: true, enableRequestHeaderTracking: true, enableResponseHeaderTracking: true, + disableCookiesUsage: true, }, }); diff --git a/frontend/src/utils/azure.ts b/frontend/src/utils/azure.ts index bf7ef7ad..85e8bdc8 100644 --- a/frontend/src/utils/azure.ts +++ b/frontend/src/utils/azure.ts @@ -7,7 +7,7 @@ import { getSession } from "next-auth/react"; export const getDatasets = async (startDate: string, endDate: string) => { const session = await getSession(); if (!session?.user) return []; - const res = await axios.get(`${process.env.NEXT_PUBLIC_NEUROFUSION_BACKEND_URL}/api/storage/search`, { + const res = await axios.get(`${process.env["NEXT_PUBLIC_NEUROFUSION_BACKEND_URL"]}/api/storage/search`, { headers: { Authorization: `Bearer ${session.user.authToken}`, }, @@ -30,7 +30,7 @@ export async function downloadDatasets(blobNames: Array, downloadStatusS if (!session?.user) return false; let zip = new JSZip(); for (let i = 0; i < blobNames.length; i++) { - const res = await axios.get(`${process.env.NEXT_PUBLIC_NEUROFUSION_BACKEND_URL}/api/storage/download`, { + const res = await axios.get(`${process.env["NEXT_PUBLIC_NEUROFUSION_BACKEND_URL"]}/api/storage/download`, { headers: { Authorization: `Bearer ${session.user.authToken}`, },