Skip to content

Commit

Permalink
🐞 fix (CHASE Frontend): implement runtime env for backend url in fron…
Browse files Browse the repository at this point in the history
…tend

branch: Branch not found
  • Loading branch information
m1212e committed Mar 9, 2024
1 parent 1255872 commit c8ceaa1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.chase.backend
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ ENV PORT=3001
# run the app
USER bun
EXPOSE 3001/tcp
ENTRYPOINT [ "bun", "main.js" ]
ENTRYPOINT [ "bun", "main.js", "--smol" ]
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion chase/frontend/.env.development
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BACKEND_URL=http://localhost:3001
NEXT_PUBLIC_BACKEND_URL=http://localhost:3001
13 changes: 10 additions & 3 deletions chase/frontend/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import "./globals.scss";
import { Inter } from "next/font/google"; // Even though Google Fonts are used – no requests are sent to Google (see NEXT.JS docs)

import { PublicEnvScript } from "next-runtime-env";
//theme
import "@/themes/theme_light.scss";
import "@/themes/theme_dark.scss";
Expand Down Expand Up @@ -50,9 +50,16 @@ export default function RootLayout({

return (
<html lang="en">
<Head>
<title>Chase</title> {/* TODO Make title work */}
<head>

This comment has been minimized.

Copy link
@m1212e

m1212e Mar 9, 2024

Author Member

@TadeSF is this change ok?

<PublicEnvScript />
</head>

{/* <Head>
<title>Chase</title>
<PublicEnvScript />
</Head>
*/}

<body className={inter.className}>
{/* <PrimeReactProvider value={{ pt: Tailwind }}> */}
<TypesafeI18n locale={locale}>
Expand Down
9 changes: 7 additions & 2 deletions chase/frontend/contexts/backend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { createContext, useContext, useState } from "react";
import { edenTreaty } from "@elysiajs/eden";
import { App } from "../../backend/src/main";
import { unstable_noStore as noStore } from "next/cache";
import { env } from "next-runtime-env";

export const BackendContext = createContext({} as BackendContextType);
export const useBackend = () => useContext(BackendContext);
Expand All @@ -12,9 +13,12 @@ export type BackendInstanceType = ReturnType<typeof edenTreaty<App>>;
//TODO
function getBackendUrl() {
noStore();
return process.env.BACKEND_URL || "https://chase-backend.dmun.de";
// return process.env.BACKEND_URL || "http://localhost:3001";
return env("NEXT_PUBLIC_BACKEND_URL") || "https://chase-backend.dmun.de";
}
setTimeout(() => {
console.log("Backend URL", getBackendUrl());

Check warning on line 19 in chase/frontend/contexts/backend.tsx

View workflow job for this annotation

GitHub Actions / biome-linter

Don't use console.log
}, 5000);


export const Backend = ({ children }: { children: React.ReactNode }) => {
const [backend, _setBackend] = useState(
Expand All @@ -35,3 +39,4 @@ export const Backend = ({ children }: { children: React.ReactNode }) => {
export interface BackendContextType {
backend: BackendInstanceType;
}

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"@biomejs/biome": "^1.5.3",
"bun-types": "latest",
"concurrently": "^8.2.2"
},
"dependencies": {
"next-runtime-env": "^3.2.0"
}
}

0 comments on commit c8ceaa1

Please sign in to comment.