Skip to content

Commit

Permalink
build: load env dynamically for app service instance (#235)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
oreHGA committed Aug 21, 2024
1 parent b469c46 commit 9190b9a
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/staging_fusion-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion frontend/.env.local

This file was deleted.

5 changes: 5 additions & 0 deletions frontend/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
2 changes: 1 addition & 1 deletion frontend/src/config/constants.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/analysis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/sitemap.xml.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ interface AuthResponse {

class AuthService {
async completeNostrLogin(publicKey: string, privateKey?: string): Promise<AuthResponse | null> {
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}`);
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/services/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/utils/appInsights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ 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"] || "<placeholder>",
extensions: [reactPlugin],
enableAutoRouteTracking: true,
disableAjaxTracking: false,
autoTrackPageVisitTime: true,
enableCorsCorrelation: true,
enableRequestHeaderTracking: true,
enableResponseHeaderTracking: true,
disableCookiesUsage: true,
},
});

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/utils/azure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
},
Expand All @@ -30,7 +30,7 @@ export async function downloadDatasets(blobNames: Array<string>, 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}`,
},
Expand Down

0 comments on commit 9190b9a

Please sign in to comment.