Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make API_URL env available in browsers #1995

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifests/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ spec:
secretKeyRef:
name: secrets-web
key: google-secret
- name: API_URL
- name: NEXT_PUBLIC_API_URL
valueFrom:
configMapKeyRef:
name: config-web
Expand Down
4 changes: 2 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const moduleExports = {
},
publicRuntimeConfig: {
APP_ENV: process.env.APP_ENV,
API_URL: process.env.API_URL,
API_URL: process.env.NEXT_PUBLIC_API_URL,
APP_URL: process.env.APP_URL,
GTM_ID: process.env.GTM_ID ?? 'GTM-TWQBXM6',
PAYPAL_CLIENT_ID: process.env.PAYPAL_CLIENT_ID,
Expand All @@ -54,7 +54,7 @@ const moduleExports = {
return [
{
source: '/api/v1/:slug*',
destination: `${process.env.API_URL ?? 'http://localhost:5010/api/v1'}/:slug*`, // Proxy to API
destination: `${process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:5010/api/v1'}/:slug*`, // Proxy to API
},
{
source: '/robots.txt',
Expand Down
7 changes: 3 additions & 4 deletions src/common/util/campaignImageUrls.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import getConfig from 'next/config'
import { CampaignFile, CampaignResponse } from 'gql/campaigns'
import { CampaignFileRole, ImageSlider } from 'components/common/campaign-file/roles'

const { publicRuntimeConfig } = getConfig()
import { API_URL } from 'service/apiClient'

export function fileUrl(file: CampaignFile) {
return `${publicRuntimeConfig.API_URL}/campaign-file/${file.id}`
return `${API_URL}/campaign-file/${file.id}`
}

/**
Expand All @@ -29,7 +28,7 @@ export function campaignSliderUrls(campaign: CampaignResponse): ImageSlider[] {
return files.map((file) => {
return {
id: file.id,
src: `${publicRuntimeConfig.API_URL}/campaign-file/${file.id}`,
src: `${API_URL}/campaign-file/${file.id}`,
fileName: file.filename.replace(fileExtensionRemoverRegex, ''),
}
})
Expand Down
6 changes: 2 additions & 4 deletions src/common/util/expenseFileUrls.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import getConfig from 'next/config'

const { publicRuntimeConfig } = getConfig()
import { API_URL } from 'service/apiClient'

export function expenseFileUrl(fileId: string) {
return `${publicRuntimeConfig.API_URL}/expenses/download-file/${fileId}`
return `${API_URL}/expenses/download-file/${fileId}`
}
5 changes: 3 additions & 2 deletions src/common/util/newsFilesUrls.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CampaignNewsFile } from 'gql/campaign-news'
import { CampaignFileRole } from 'components/common/campaign-file/roles'
import getConfig from 'next/config'
import { API_URL } from 'service/apiClient'

const { publicRuntimeConfig } = getConfig()

Expand All @@ -13,7 +14,7 @@ export function GetArticleDocuments(files: CampaignNewsFile[]) {
.map((file) => {
return {
id: file.id,
fileUrl: `${publicRuntimeConfig.API_URL}/campaign-news-file/${file.id}`,
fileUrl: `${API_URL}/campaign-news-file/${file.id}`,
fileName: file.filename.replace(fileExtensionRemoverRegex, ''),
}
})
Expand All @@ -26,7 +27,7 @@ export function GetArticleGalleryPhotos(files: CampaignNewsFile[]) {
.map((file) => {
return {
id: file.id,
src: `${publicRuntimeConfig.API_URL}/campaign-news-file/${file.id}`,
src: `${API_URL}/campaign-news-file/${file.id}`,
fileName: file.filename.replace(fileExtensionRemoverRegex, ''),
}
})
Expand Down
5 changes: 1 addition & 4 deletions src/service/apiClient.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import Axios from 'axios'
import LRU from 'lru-cache'
import getConfig from 'next/config'
import { makeUseAxios } from 'axios-hooks'

const {
publicRuntimeConfig: { API_URL },
} = getConfig()
export const API_URL = process.env.NEXT_PUBLIC_API_URL

const cache = new LRU({ max: 10 })
export const apiClient = Axios.create({ baseURL: `${API_URL}` })
Expand Down
Loading