Skip to content

Commit fe085b5

Browse files
committed
fix: environment variable API_URL can't be changed
1 parent 958b79d commit fe085b5

File tree

5 files changed

+11
-17
lines changed

5 files changed

+11
-17
lines changed

frontend/next.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,4 @@ module.exports = withPWA({
1818
output: "standalone", env: {
1919
VERSION: version,
2020
},
21-
serverRuntimeConfig: {
22-
apiURL: process.env.API_URL ?? 'http://localhost:8080',
23-
},
2421
});

frontend/src/pages/_app.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import { ModalsProvider } from "@mantine/modals";
99
import { Notifications } from "@mantine/notifications";
1010
import axios from "axios";
1111
import { getCookie, setCookie } from "cookies-next";
12+
import moment from "moment";
13+
import "moment/min/locales";
1214
import { GetServerSidePropsContext } from "next";
1315
import type { AppProps } from "next/app";
14-
import getConfig from "next/config";
1516
import Head from "next/head";
1617
import { useRouter } from "next/router";
1718
import { useEffect, useRef, useState } from "react";
@@ -29,8 +30,6 @@ import Config from "../types/config.type";
2930
import { CurrentUser } from "../types/user.type";
3031
import i18nUtil from "../utils/i18n.util";
3132
import userPreferences from "../utils/userPreferences.util";
32-
import "moment/min/locales";
33-
import moment from "moment";
3433

3534
const excludeDefaultLayoutRoutes = ["/admin/config/[category]"];
3635

@@ -44,7 +43,7 @@ function App({ Component, pageProps }: AppProps) {
4443
const [route, setRoute] = useState<string>(pageProps.route);
4544

4645
const [configVariables, setConfigVariables] = useState<Config[]>(
47-
pageProps.configVariables,
46+
pageProps.configVariables
4847
);
4948

5049
useEffect(() => {
@@ -54,7 +53,7 @@ function App({ Component, pageProps }: AppProps) {
5453
useEffect(() => {
5554
const interval = setInterval(
5655
async () => await authService.refreshAccessToken(),
57-
2 * 60 * 1000, // 2 minutes
56+
2 * 60 * 1000 // 2 minutes
5857
);
5958

6059
return () => clearInterval(interval);
@@ -154,8 +153,6 @@ function App({ Component, pageProps }: AppProps) {
154153
// Fetch user and config variables on server side when the first request is made
155154
// These will get passed as a page prop to the App component and stored in the contexts
156155
App.getInitialProps = async ({ ctx }: { ctx: GetServerSidePropsContext }) => {
157-
const { apiURL } = getConfig().serverRuntimeConfig;
158-
159156
let pageProps: {
160157
user?: CurrentUser;
161158
configVariables?: Config[];
@@ -169,6 +166,7 @@ App.getInitialProps = async ({ ctx }: { ctx: GetServerSidePropsContext }) => {
169166
};
170167

171168
if (ctx.req) {
169+
const apiURL = process.env.API_URL || "http://localhost:8080";
172170
const cookieHeader = ctx.req.headers.cookie;
173171

174172
pageProps.user = await axios(`${apiURL}/api/users/me`, {
@@ -182,7 +180,7 @@ App.getInitialProps = async ({ ctx }: { ctx: GetServerSidePropsContext }) => {
182180
pageProps.route = ctx.req.url;
183181

184182
const requestLanguage = i18nUtil.getLanguageFromAcceptHeader(
185-
ctx.req.headers["accept-language"],
183+
ctx.req.headers["accept-language"]
186184
);
187185

188186
pageProps.language = ctx.req.cookies["language"] ?? requestLanguage;

frontend/src/pages/api/[...all].tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { NextApiRequest, NextApiResponse } from "next";
22
import httpProxyMiddleware from "next-http-proxy-middleware";
3-
import getConfig from "next/config";
43

54
export const config = {
65
api: {
@@ -9,7 +8,7 @@ export const config = {
98
},
109
};
1110

12-
const { apiURL } = getConfig().serverRuntimeConfig;
11+
const apiURL = process.env.API_URL || "http://localhost:8080";
1312

1413
// A proxy to the API server only used in development.
1514
// In production this route gets overridden by Caddy.

reverse-proxy/Caddyfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
:3000 {
22
# Reverse proxy for /api
3-
reverse_proxy /api/* http://localhost:8080
3+
reverse_proxy /api/* http://localhost:{$BACKEND_PORT:8080}
44

55
# Reverse proxy for all other requests
6-
reverse_proxy http://localhost:3333
6+
reverse_proxy http://localhost:{$PORT:3333}
77
}

reverse-proxy/Caddyfile.trust-proxy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
:3000 {
2-
reverse_proxy /* http://localhost:3333 {
2+
reverse_proxy /* http://localhost:{$PORT:3333} {
33
trusted_proxies 0.0.0.0/0
44
}
55

6-
reverse_proxy /api/* http://localhost:8080 {
6+
reverse_proxy /api/* http://localhost:{$BACKEND_PORT:8080} {
77
trusted_proxies 0.0.0.0/0
88
}
99

0 commit comments

Comments
 (0)