diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 9e08820..e82f5a2 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -48,5 +48,6 @@ jobs: - run: pnpm install - name: Build the application env: - BACKEND_URL: "http://localhost:8080" + NEXT_PUBLIC_API_URL: "http://localhost:8080" + BACK_END_URL: "http://localhost:8080" run: pnpm build diff --git a/README.md b/README.md index 74fdb5e..6a8ef76 100644 --- a/README.md +++ b/README.md @@ -110,10 +110,10 @@ Set up the application environment variables by running the following script: scripts/init_environments.sh ``` -This script generates environment variables, including BACKEND_URL, to establish the communication between the client and server. Example +This script generates environment variables, including NEXT_PUBLIC_API_URL, to establish the communication between the client and server. Example ``` -BACKEND_URL=http://localhost:8080 +NEXT_PUBLIC_API_URL=http://localhost:8080 ``` We recommend running the `scripts/all.sh` script, as it streamlines the process by checking your environment settings and performing all necessary configurations, removing the need to execute multiple scripts manually. diff --git a/next.config.mjs b/next.config.mjs index a87e580..8b1fd47 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -6,7 +6,7 @@ const nextConfig = { fallback: [ { source: "/api/:path*", - destination: `${process.env.BACKEND_URL}/api/:path*`, + destination: `${process.env.NEXT_PUBLIC_API_URL}/api/:path*`, }, ], }; diff --git a/package.json b/package.json index 3fedb04..ec28c9e 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "nanoid": "^5.0.9", "next": "^15.1.2", "next-auth": "5.0.0-beta.25", + "next-runtime-env": "^3.2.2", "next-themes": "^0.4.4", "nuqs": "^2.2.3", "react": "^19.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f770a3f..cbeb93a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -169,6 +169,9 @@ importers: next-auth: specifier: 5.0.0-beta.25 version: 5.0.0-beta.25(next@15.1.2(react-dom@19.0.0(react@19.0.0))(react@19.0.0))(react@19.0.0) + next-runtime-env: + specifier: ^3.2.2 + version: 3.2.2(next@15.1.2(react-dom@19.0.0(react@19.0.0))(react@19.0.0))(react@19.0.0) next-themes: specifier: ^0.4.4 version: 0.4.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0) @@ -4254,6 +4257,15 @@ packages: nodemailer: optional: true + next-runtime-env@3.2.2: + resolution: + { + integrity: sha512-S5S6NxIf3XeaVc9fLBN2L5Jzu+6dLYCXeOaPQa1RzKRYlG2BBayxXOj6A4VsciocyNkJMazW1VAibtbb1/ZjAw==, + } + peerDependencies: + next: ^14 + react: ^18 + next-themes@0.4.4: resolution: { @@ -8373,6 +8385,11 @@ snapshots: next: 15.1.2(react-dom@19.0.0(react@19.0.0))(react@19.0.0) react: 19.0.0 + next-runtime-env@3.2.2(next@15.1.2(react-dom@19.0.0(react@19.0.0))(react@19.0.0))(react@19.0.0): + dependencies: + next: 15.1.2(react-dom@19.0.0(react@19.0.0))(react@19.0.0) + react: 19.0.0 + next-themes@0.4.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0): dependencies: react: 19.0.0 diff --git a/scripts/docker_deployment.sh b/scripts/docker_deployment.sh index 1a596ff..2854f2e 100755 --- a/scripts/docker_deployment.sh +++ b/scripts/docker_deployment.sh @@ -24,14 +24,14 @@ docker tag ${IMAGE_NAME} ${REMOTE_REPO}:${TAG} docker tag ${IMAGE_NAME} ${REMOTE_REPO}:latest # Step 3: Log in to the Docker repository (Docker Hub by default) -echo "Logging into Docker repository..." -docker login || { echo "Login failed"; exit 1; } - -# Step 4: Push both tags to the remote repository -echo "Pushing Docker image to remote repository with tag '${TAG}'..." -docker push ${REMOTE_REPO}:${TAG} - -echo "Pushing Docker image to remote repository with tag 'latest'..." -docker push ${REMOTE_REPO}:latest - -echo "Docker image has been pushed successfully with tags '${TAG}' and 'latest'." +#echo "Logging into Docker repository..." +#docker login || { echo "Login failed"; exit 1; } +# +## Step 4: Push both tags to the remote repository +#echo "Pushing Docker image to remote repository with tag '${TAG}'..." +#docker push ${REMOTE_REPO}:${TAG} +# +#echo "Pushing Docker image to remote repository with tag 'latest'..." +#docker push ${REMOTE_REPO}:latest +# +#echo "Docker image has been pushed successfully with tags '${TAG}' and 'latest'." diff --git a/scripts/init_environments.sh b/scripts/init_environments.sh index 710c00d..9d5c20b 100755 --- a/scripts/init_environments.sh +++ b/scripts/init_environments.sh @@ -33,7 +33,8 @@ while true; do done # Append to the .env.local file -echo "BACKEND_URL=\"$backend_server\"" >> "$output_file" +echo "NEXT_PUBLIC_API_URL=\"$backend_server\"" >> "$output_file" +echo "BACK_END_URL=\"$backend_server\"" >> "$output_file" # Run npx auth and append its output to .env diff --git a/src/app/(auth)/login/page.tsx b/src/app/(auth)/login/page.tsx index 7211c0c..9d90135 100644 --- a/src/app/(auth)/login/page.tsx +++ b/src/app/(auth)/login/page.tsx @@ -1,6 +1,8 @@ import LoginForm from "@/components/auth/login-form"; +import { BACK_END_URL } from "@/lib/constants"; -const LoginPage = () => { +const LoginPage = async () => { + console.log(`BACK_END ${BACK_END_URL}`); return ; }; export default LoginPage; diff --git a/src/app/layout.tsx b/src/app/layout.tsx index c36de8a..bbb0cdd 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -3,11 +3,10 @@ import "./theme.css"; import type { Metadata } from "next"; import { Inter } from "next/font/google"; +import { PublicEnvScript } from "next-runtime-env"; -import AutoInitBackendApi from "@/components/init-api-backend"; import { Toaster } from "@/components/ui/toaster"; import { TooltipProvider } from "@/components/ui/tooltip"; -import { setBackendUrl, setBaseUrl } from "@/lib/runtime-variables"; import { ErrorProvider } from "@/providers/error-provider"; import ReactQueryProvider from "@/providers/react-query-provider"; import { ThemeProvider } from "@/providers/theme-provider"; @@ -19,44 +18,21 @@ export const metadata: Metadata = { description: "FlowInquiry dashboard", }; -const RootLayout = async ({ - children, -}: Readonly<{ - children: React.ReactNode; -}>) => { - const backendUrl = process.env.BACKEND_URL; - if (!backendUrl) { - throw new Error("BACKEND_URL is not defined in the environment"); - } - setBackendUrl(backendUrl); - - // Base url is the mandatory field in environments except local - const baseUrl = process.env.BASE_URL; - setBaseUrl(baseUrl); - +const RootLayout = async ({ children }: { children: React.ReactNode }) => { return ( + FlowInquiry - Ticket Management - {/* Favicon for modern browsers */} - {/* Fallback favicon for older browsers */} -