Skip to content

Commit a4809c2

Browse files
Merge pull request #9 from akshayanv/add-prod-runtime-NEXT_PUBLIC-vars
Use NEXT_PUBLIC env vars as runtime vars for prod builds
2 parents c499f3f + cd537b8 commit a4809c2

File tree

7 files changed

+106
-9
lines changed

7 files changed

+106
-9
lines changed

components/Chat/ChatHeader.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use client'
22

3+
import { env } from 'next-runtime-env'
4+
35
import React, { useContext, useState, useRef, useEffect } from 'react';
46
import {
57
IconArrowsSort,
@@ -15,7 +17,7 @@ import { getWorkflowName } from '@/utils/app/helper';
1517

1618
export const ChatHeader = ({ webSocketModeRef = {} }) => {
1719
const [isMenuOpen, setIsMenuOpen] = useState(false);
18-
const [isExpanded, setIsExpanded] = useState(process?.env?.NEXT_PUBLIC_RIGHT_MENU_OPEN === 'true' ? true : false);
20+
const [isExpanded, setIsExpanded] = useState(env('NEXT_PUBLIC_RIGHT_MENU_OPEN') === 'true' || process?.env?.NEXT_PUBLIC_RIGHT_MENU_OPEN === 'true' ? true : false);
1921
const menuRef = useRef(null);
2022

2123
const workflow = getWorkflowName()

next.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
const { configureRuntimeEnv } = require('next-runtime-env/build/configure');
2+
13
const nextConfig = {
4+
env: {
5+
...configureRuntimeEnv(),
6+
},
27
output: 'standalone',
38
typescript: {
49
// !! WARN !!

package-lock.json

Lines changed: 87 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"prettier-plugin-tailwindcss": "^0.2.5",
7171
"tailwindcss": "^3.3.3",
7272
"typescript": "4.9.5",
73-
"vitest": "^0.29.7"
73+
"vitest": "^0.29.7",
74+
"next-runtime-env": "^1.3.0"
7475
}
7576
}

pages/_document.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { DocumentProps, Head, Html, Main, NextScript } from 'next/document';
22
import i18nextConfig from '../next-i18next.config';
3-
43
type Props = DocumentProps & {
54
// add custom document props
65
};
@@ -13,6 +12,7 @@ export default function Document(props: Props) {
1312
<Head>
1413
<meta name="apple-mobile-web-app-capable" content="yes" />
1514
<meta name="apple-mobile-web-app-title" content="AIQ Toolkit-UI"></meta>
15+
<script src="/__ENV.js" />
1616
</Head>
1717
<body>
1818
<Main />

pages/api/home/home.state.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Conversation, Message } from '@/types/chat';
22
import { FolderInterface } from '@/types/folder';
33
import { t } from 'i18next';
4+
import { env } from 'next-runtime-env'
45

56
export interface HomeInitialState {
67
loading: boolean;
@@ -40,14 +41,14 @@ export const initialState: HomeInitialState = {
4041
currentFolder: undefined,
4142
messageError: false,
4243
searchTerm: '',
43-
chatHistory: process?.env?.NEXT_PUBLIC_CHAT_HISTORY_DEFAULT_ON === 'true' || false,
44-
chatCompletionURL: process?.env?.NEXT_PUBLIC_HTTP_CHAT_COMPLETION_URL || 'http://127.0.0.1:8000/chat/stream',
45-
webSocketMode: process?.env?.NEXT_PUBLIC_WEB_SOCKET_DEFAULT_ON === 'true' || false,
44+
chatHistory: env('NEXT_PUBLIC_CHAT_HISTORY_DEFAULT_ON') === 'true' || process?.env?.NEXT_PUBLIC_CHAT_HISTORY_DEFAULT_ON === 'true' ? true : false,
45+
chatCompletionURL: env('NEXT_PUBLIC_HTTP_CHAT_COMPLETION_URL') || process?.env?.NEXT_PUBLIC_HTTP_CHAT_COMPLETION_URL || 'http://127.0.0.1:8000/chat/stream',
46+
webSocketMode: env('NEXT_PUBLIC_WEB_SOCKET_DEFAULT_ON') === 'true' || process?.env?.NEXT_PUBLIC_WEB_SOCKET_DEFAULT_ON === 'true' ? true : false,
4647
webSocketConnected: false,
47-
webSocketURL: process?.env?.NEXT_PUBLIC_WEBSOCKET_CHAT_COMPLETION_URL || 'ws://127.0.0.1:8000/websocket',
48+
webSocketURL: env('NEXT_PUBLIC_WEBSOCKET_CHAT_COMPLETION_URL') || process?.env?.NEXT_PUBLIC_WEBSOCKET_CHAT_COMPLETION_URL || 'ws://127.0.0.1:8000/websocket',
4849
webSocketSchema: 'chat_stream',
4950
webSocketSchemas: ['chat_stream', 'chat', 'generate_stream', 'generate'],
50-
enableIntermediateSteps: process?.env?.NEXT_PUBLIC_ENABLE_INTERMEDIATE_STEPS ? process.env.NEXT_PUBLIC_ENABLE_INTERMEDIATE_STEPS === 'true' : true,
51+
enableIntermediateSteps: env('NEXT_PUBLIC_ENABLE_INTERMEDIATE_STEPS') === 'true' || process?.env?.NEXT_PUBLIC_ENABLE_INTERMEDIATE_STEPS === 'true' ? true : false,
5152
expandIntermediateSteps: false,
5253
intermediateStepOverride: true,
5354
autoScroll: true,

utils/app/helper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { v4 as uuidv4 } from 'uuid';
2+
import { env } from 'next-runtime-env'
23
export const getInitials = (fullName = '') => {
34
if (!fullName) {
45
return "";
@@ -86,7 +87,7 @@ export const getURLQueryParam = ({ param = '' }) => {
8687

8788

8889
export const getWorkflowName = () => {
89-
const workflow = getURLQueryParam({ param: 'workflow' }) || process?.env?.NEXT_PUBLIC_WORKFLOW || 'AIQ Toolkit';
90+
const workflow = getURLQueryParam({ param: 'workflow' }) || env('NEXT_PUBLIC_WORKFLOW') || process?.env?.NEXT_PUBLIC_WORKFLOW || 'AIQ Toolkit';
9091
return workflow
9192
}
9293

0 commit comments

Comments
 (0)