Skip to content

Commit 1586a98

Browse files
fix: env vars from compose to next client-side #attempt2
1 parent d9b6d51 commit 1586a98

File tree

16 files changed

+70
-51
lines changed

16 files changed

+70
-51
lines changed

app/auth/page.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import Image from "next/image";
44
import Link from "next/link";
55
import { useState } from "react";
6+
import { env } from "next-runtime-env";
67

78
export default function Auth() {
89
const [email, setEmail] = useState("");
@@ -21,8 +22,8 @@ export default function Auth() {
2122

2223
try {
2324
const response = await fetch(
24-
(process.env.NEXT_PUBLIC_AUTH_BASE_URL ??
25-
"http://localhost:5000") + "/api/login",
25+
(env("NEXT_PUBLIC_AUTH_BASE_URL") ?? "http://localhost:5000") +
26+
"/api/login",
2627
{
2728
method: "POST",
2829
headers: {

app/auth/register/page.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Image from "next/image";
33
import Link from "next/link";
44
import { useRouter } from "next/navigation";
55
import { useState } from "react";
6+
import { env } from "next-runtime-env";
67

78
export default function Register() {
89
const [formData, setFormData] = useState({
@@ -38,8 +39,8 @@ export default function Register() {
3839

3940
try {
4041
const res = await fetch(
41-
(process.env.NEXT_PUBLIC_AUTH_BASE_URL ??
42-
"http://localhost:5000") + "/api/register",
42+
(env("NEXT_PUBLIC_AUTH_BASE_URL") ?? "http://localhost:5000") +
43+
"/api/register",
4344
{
4445
method: "POST",
4546
headers: {

app/auth/register/verify/page.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import Image from "next/image";
44
import { useRouter, useSearchParams } from "next/navigation";
55
import { useState } from "react";
6+
import { env } from "next-runtime-env";
67

78
export default function VerifyOTP() {
89
const [otp, setOtp] = useState("");
@@ -21,8 +22,8 @@ export default function VerifyOTP() {
2122

2223
try {
2324
const response = await fetch(
24-
(process.env.NEXT_PUBLIC_AUTH_BASE_URL ??
25-
"http://localhost:5000") + "/api/register/verify",
25+
(env("NEXT_PUBLIC_AUTH_BASE_URL") ?? "http://localhost:5000") +
26+
"/api/register/verify",
2627
{
2728
method: "POST",
2829
headers: {

app/bin/ea/[id]/page.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Image from "next/image";
66
import Link from "next/link";
77
import { useParams } from "next/navigation";
88
import { useEffect, useState, useRef } from "react";
9+
import { env } from "next-runtime-env";
910

1011
export default function Execution() {
1112
const [data, setData] = useState(null);
@@ -45,7 +46,7 @@ export default function Execution() {
4546

4647
// Use NEXT_PUBLIC prefix for browser access
4748
const backendBaseUrl =
48-
process.env.NEXT_PUBLIC_BACKEND_BASE_URL ?? "http://localhost:5002";
49+
env("NEXT_PUBLIC_BACKEND_BASE_URL") ?? "http://localhost:5002";
4950
const sseUrl = `${backendBaseUrl.replace(/\/$/, "")}/api/runs/logs`;
5051

5152
try {
@@ -222,7 +223,7 @@ export default function Execution() {
222223
const fetchData = () => {
223224
// Use NEXT_PUBLIC prefix for browser access
224225
const backendBaseUrl =
225-
process.env.NEXT_PUBLIC_BACKEND_BASE_URL ?? "http://localhost:5002";
226+
env("NEXT_PUBLIC_BACKEND_BASE_URL") ?? "http://localhost:5002";
226227
console.log("Fetching execution status for Run ID:", id);
227228
fetch(`${backendBaseUrl}/api/runs/run`, {
228229
method: "POST",
@@ -305,7 +306,7 @@ export default function Execution() {
305306
useEffect(() => {
306307
// Use NEXT_PUBLIC prefix for browser access
307308
const minioBaseUrl =
308-
process.env.NEXT_PUBLIC_MINIO_BASE_URL ?? "http://localhost:9000";
309+
env("NEXT_PUBLIC_MINIO_BASE_URL") ?? "http://localhost:9000";
309310

310311
const fetchInputParams = () => {
311312
fetch(`${minioBaseUrl}/code/${id}/input.json`)
@@ -360,7 +361,7 @@ export default function Execution() {
360361
const fetchLogsContent = () => {
361362
// Use NEXT_PUBLIC prefix for browser access
362363
const minioBaseUrl =
363-
process.env.NEXT_PUBLIC_MINIO_BASE_URL ?? "http://localhost:9000";
364+
env("NEXT_PUBLIC_MINIO_BASE_URL") ?? "http://localhost:9000";
364365
fetch(`${minioBaseUrl}/code/${id}/logbook.txt`)
365366
.then((response) => {
366367
if (!response.ok)
@@ -378,7 +379,7 @@ export default function Execution() {
378379
const fetchBestFitness = () => {
379380
// Use NEXT_PUBLIC prefix for browser access
380381
const minioBaseUrl =
381-
process.env.NEXT_PUBLIC_MINIO_BASE_URL ?? "http://localhost:9000";
382+
env("NEXT_PUBLIC_MINIO_BASE_URL") ?? "http://localhost:9000";
382383
fetch(`${minioBaseUrl}/code/${id}/best.txt`)
383384
.then((response) => {
384385
if (!response.ok) throw new Error("Failed to fetch best.txt");
@@ -395,7 +396,7 @@ export default function Execution() {
395396
e.preventDefault();
396397
// Use NEXT_PUBLIC prefix for browser access
397398
const backendBaseUrl =
398-
process.env.NEXT_PUBLIC_BACKEND_BASE_URL ?? "http://localhost:5002";
399+
env("NEXT_PUBLIC_BACKEND_BASE_URL") ?? "http://localhost:5002";
399400

400401
fetch(`${backendBaseUrl}/api/runs/share`, {
401402
method: "POST",
@@ -455,7 +456,7 @@ export default function Execution() {
455456
? "Live Execution Logs"
456457
: "Final Generation Wise Logs";
457458
const minioBaseUrl =
458-
process.env.NEXT_PUBLIC_MINIO_BASE_URL ?? "http://localhost:9000"; // Define once
459+
env("NEXT_PUBLIC_MINIO_BASE_URL") ?? "http://localhost:9000"; // Define once
459460

460461
return (
461462
<main className="flex flex-col items-center justify-center min-h-screen font-[family-name:var(--font-geist-mono)] p-4 sm:p-8 bg-gray-100">
@@ -640,7 +641,7 @@ export default function Execution() {
640641
<h3 className="text-xl font-bold text-gray-800">
641642
Code
642643
</h3>
643-
{process.env.NEXT_PUBLIC_AI === "true" && (
644+
{env("NEXT_PUBLIC_AI") === "true" && (
644645
<Link
645646
href={`/explain/${id}`}
646647
className="inline-flex items-center justify-center gap-2 rounded-full px-4 py-2 text-xs sm:text-sm font-medium text-slate-700 border border-slate-300 shadow-sm transition-all duration-200 ease-in-out hover:bg-slate-200 focus:outline-none focus:ring-2 focus:ring-blue-500 active:bg-slate-300"

app/bin/gp/[id]/page.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Image from "next/image";
66
import Link from "next/link";
77
import { useParams } from "next/navigation";
88
import { useEffect, useState, useRef } from "react";
9+
import { env } from "next-runtime-env";
910

1011
export default function GPRunResult() {
1112
const [data, setData] = useState(null); // Stores full run data if needed later
@@ -30,7 +31,7 @@ export default function GPRunResult() {
3031
// --- Function to Fetch Status and Control SSE (Defined early) ---
3132
const fetchData = () => {
3233
const backendBaseUrl =
33-
process.env.NEXT_PUBLIC_BACKEND_BASE_URL ?? "http://localhost:5002";
34+
env("NEXT_PUBLIC_BACKEND_BASE_URL") ?? "http://localhost:5002";
3435
console.log("Fetching execution status for GP Run ID:", id);
3536
fetch(`${backendBaseUrl}/api/runs/run`, {
3637
method: "POST",
@@ -123,7 +124,7 @@ export default function GPRunResult() {
123124
const signal = sseAbortControllerRef.current.signal;
124125

125126
const backendBaseUrl =
126-
process.env.NEXT_PUBLIC_BACKEND_BASE_URL ?? "http://localhost:5002";
127+
env("NEXT_PUBLIC_BACKEND_BASE_URL") ?? "http://localhost:5002";
127128
const sseUrl = `${backendBaseUrl.replace(/\/$/, "")}/api/runs/logs`; // Updated URL
128129

129130
try {
@@ -311,7 +312,7 @@ export default function GPRunResult() {
311312
// --- Fetch Static Content & Initial Status ---
312313
useEffect(() => {
313314
const minioBaseUrl =
314-
process.env.NEXT_PUBLIC_MINIO_BASE_URL ?? "http://localhost:9000";
315+
env("NEXT_PUBLIC_MINIO_BASE_URL") ?? "http://localhost:9000";
315316
const fetchInputParams = () => {
316317
fetch(`${minioBaseUrl}/code/${id}/input.json`)
317318
.then((response) =>
@@ -356,7 +357,7 @@ export default function GPRunResult() {
356357
// --- Fetch Final Log Content ---
357358
const fetchLogsContent = () => {
358359
const minioBaseUrl =
359-
process.env.NEXT_PUBLIC_MINIO_BASE_URL ?? "http://localhost:9000";
360+
env("NEXT_PUBLIC_MINIO_BASE_URL") ?? "http://localhost:9000";
360361
fetch(`${minioBaseUrl}/code/${id}/logbook.txt`)
361362
.then((response) =>
362363
response.ok
@@ -373,7 +374,7 @@ export default function GPRunResult() {
373374
// --- Fetch Final Best Fitness/Expression ---
374375
const fetchBestFitness = () => {
375376
const minioBaseUrl =
376-
process.env.NEXT_PUBLIC_MINIO_BASE_URL ?? "http://localhost:9000";
377+
env("NEXT_PUBLIC_MINIO_BASE_URL") ?? "http://localhost:9000";
377378
// GP results are often in best.txt as the expression
378379
fetch(`${minioBaseUrl}/code/${id}/best.txt`)
379380
.then((response) =>
@@ -407,7 +408,7 @@ export default function GPRunResult() {
407408
const handleShareSubmit = (e) => {
408409
e.preventDefault();
409410
const backendBaseUrl =
410-
process.env.NEXT_PUBLIC_BACKEND_BASE_URL ?? "http://localhost:5002";
411+
env("NEXT_PUBLIC_BACKEND_BASE_URL") ?? "http://localhost:5002";
411412
fetch(`${backendBaseUrl}/api/runs/share`, {
412413
method: "POST",
413414
headers: { "Content-Type": "application/json" },
@@ -467,7 +468,7 @@ export default function GPRunResult() {
467468
? "Live Execution Logs"
468469
: "Final Generation Wise Logs";
469470
const minioBaseUrl =
470-
process.env.NEXT_PUBLIC_MINIO_BASE_URL ?? "http://localhost:9000";
471+
env("NEXT_PUBLIC_MINIO_BASE_URL") ?? "http://localhost:9000";
471472

472473
return (
473474
<main className="flex flex-col items-center justify-center min-h-screen font-[family-name:var(--font-geist-mono)] p-4 sm:p-8 bg-gray-100">
@@ -644,7 +645,7 @@ export default function GPRunResult() {
644645
Code
645646
</h3>
646647
{/* ... Ask AI Button ... */}
647-
{process.env.NEXT_PUBLIC_AI === "true" && (
648+
{env("NEXT_PUBLIC_AI") === "true" && (
648649
<Link
649650
href={`/explain/${id}`}
650651
className="inline-flex items-center justify-center gap-2 rounded-full px-4 py-2 text-xs sm:text-sm font-medium text-slate-700 border border-slate-300 shadow-sm transition-all duration-200 ease-in-out hover:bg-slate-200 focus:outline-none focus:ring-2 focus:ring-blue-500 active:bg-slate-300"

app/bin/ml/[id]/page.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Image from "next/image";
66
import Link from "next/link";
77
import { useParams } from "next/navigation";
88
import { useEffect, useState, useRef } from "react";
9+
import { env } from "next-runtime-env";
910

1011
export default function MLExecResult() {
1112
// --- State Variables ---
@@ -32,7 +33,7 @@ export default function MLExecResult() {
3233
const fetchData = () => {
3334
// Use NEXT_PUBLIC prefix for browser access
3435
const backendBaseUrl =
35-
process.env.NEXT_PUBLIC_BACKEND_BASE_URL ?? "http://localhost:5002";
36+
env("NEXT_PUBLIC_BACKEND_BASE_URL") ?? "http://localhost:5002";
3637
console.log("Fetching execution status for ML Run ID:", id);
3738
fetch(`${backendBaseUrl}/api/runs/run`, {
3839
method: "POST",
@@ -125,7 +126,7 @@ export default function MLExecResult() {
125126
const signal = sseAbortControllerRef.current.signal;
126127

127128
const backendBaseUrl =
128-
process.env.NEXT_PUBLIC_BACKEND_BASE_URL ?? "http://localhost:5002";
129+
env("NEXT_PUBLIC_BACKEND_BASE_URL") ?? "http://localhost:5002";
129130
const sseUrl = `${backendBaseUrl.replace(/\/$/, "")}/api/runs/logs`; // Updated URL
130131

131132
try {
@@ -314,7 +315,7 @@ export default function MLExecResult() {
314315
// --- Fetch Static Content & Initial Status ---
315316
useEffect(() => {
316317
const minioBaseUrl =
317-
process.env.NEXT_PUBLIC_MINIO_BASE_URL ?? "http://localhost:9000";
318+
env("NEXT_PUBLIC_MINIO_BASE_URL") ?? "http://localhost:9000";
318319
const fetchInputParams = () => {
319320
fetch(`${minioBaseUrl}/code/${id}/input.json`)
320321
.then((response) =>
@@ -359,7 +360,7 @@ export default function MLExecResult() {
359360
// --- Fetch Final Log Content ---
360361
const fetchLogsContent = () => {
361362
const minioBaseUrl =
362-
process.env.NEXT_PUBLIC_MINIO_BASE_URL ?? "http://localhost:9000";
363+
env("NEXT_PUBLIC_MINIO_BASE_URL") ?? "http://localhost:9000";
363364
fetch(`${minioBaseUrl}/code/${id}/logbook.txt`)
364365
.then((response) =>
365366
response.ok
@@ -377,7 +378,7 @@ export default function MLExecResult() {
377378
const fetchBestContent = () => {
378379
// Renamed function
379380
const minioBaseUrl =
380-
process.env.NEXT_PUBLIC_MINIO_BASE_URL ?? "http://localhost:9000";
381+
env("NEXT_PUBLIC_MINIO_BASE_URL") ?? "http://localhost:9000";
381382
fetch(`${minioBaseUrl}/code/${id}/best.txt`) // Assuming best ML results are in best.txt
382383
.then((response) =>
383384
response.ok
@@ -410,7 +411,7 @@ export default function MLExecResult() {
410411
const handleShareSubmit = (e) => {
411412
e.preventDefault();
412413
const backendBaseUrl =
413-
process.env.NEXT_PUBLIC_BACKEND_BASE_URL ?? "http://localhost:5002";
414+
env("NEXT_PUBLIC_BACKEND_BASE_URL") ?? "http://localhost:5002";
414415
fetch(`${backendBaseUrl}/api/runs/share`, {
415416
method: "POST",
416417
headers: { "Content-Type": "application/json" },
@@ -470,7 +471,7 @@ export default function MLExecResult() {
470471
? "Live Execution Logs"
471472
: "Execution Logs"; // Changed final log title slightly
472473
const minioBaseUrl =
473-
process.env.NEXT_PUBLIC_MINIO_BASE_URL ?? "http://localhost:9000";
474+
env("NEXT_PUBLIC_MINIO_BASE_URL") ?? "http://localhost:9000";
474475

475476
return (
476477
<main className="flex flex-col items-center justify-center min-h-screen font-[family-name:var(--font-geist-mono)] p-4 sm:p-8 bg-gray-100">
@@ -647,7 +648,7 @@ export default function MLExecResult() {
647648
Code
648649
</h3>
649650
{/* ... Ask AI Button ... */}
650-
{process.env.NEXT_PUBLIC_AI === "true" && (
651+
{env("NEXT_PUBLIC_AI") === "true" && (
651652
<Link
652653
href={`/explain/${id}`}
653654
className="inline-flex items-center justify-center gap-2 rounded-full px-4 py-2 text-xs sm:text-sm font-medium text-slate-700 border border-slate-300 shadow-sm transition-all duration-200 ease-in-out hover:bg-slate-200 focus:outline-none focus:ring-2 focus:ring-blue-500 active:bg-slate-300"

app/bin/page.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useEffect, useState } from "react";
44
import Link from "next/link";
55
import Image from "next/image";
66
import { DnaIcon, Loader2, LogOut } from "lucide-react";
7+
import { env } from "next-runtime-env";
78

89
export default function Results() {
910
const [userData, setUserData] = useState({});
@@ -23,7 +24,7 @@ export default function Results() {
2324

2425
// Fetch the run data
2526
fetch(
26-
(process.env.NEXT_PUBLIC_BACKEND_BASE_URL ??
27+
(env("NEXT_PUBLIC_BACKEND_BASE_URL") ??
2728
"http://localhost:5002") + "/api/runs",
2829
{
2930
method: "GET",
@@ -198,7 +199,7 @@ export default function Results() {
198199
<div className="aspect-w-1 aspect-h-1 relative overflow-hidden rounded-md mb-4">
199200
<Image
200201
src={
201-
`${process.env.NEXT_PUBLIC_MINIO_BASE_URL ?? "http://localhost:9000"}/code/${run.id}/` +
202+
`${env("NEXT_PUBLIC_MINIO_BASE_URL") ?? "http://localhost:9000"}/code/${run.id}/` +
202203
(runType ===
203204
"ea"
204205
? "fitness_plot.png"

0 commit comments

Comments
 (0)