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

refactor(env): optimised the code #122

Merged
merged 2 commits into from
Oct 30, 2024
Merged
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
35 changes: 13 additions & 22 deletions frontend/lib/env.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
import 'server-only';

export let VECTOR_INDEX_HOST = '';
// Let open source users could one click deploy
if (process.env.VECTOR_INDEX_HOST) {
VECTOR_INDEX_HOST = process.env.VECTOR_INDEX_HOST;
} else if (process.env.VECTOR_HOST) {
VECTOR_INDEX_HOST = process.env.VECTOR_HOST;
} else if (process.env.MEMFREE_HOST) {
VECTOR_INDEX_HOST = `${process.env.MEMFREE_HOST}/vector`;
} else {
throw new Error('Neither VECTOR_INDEX_HOST, VECTOR_HOST, nor MEMFREE_HOST is defined');
}

const memfreeHost = process.env.MEMFREE_HOST;
export let VECTOR_HOST = '';
// Let open source users could one click deploy
if (process.env.VECTOR_HOST) {
VECTOR_HOST = process.env.VECTOR_HOST;
} else if (memfreeHost) {
VECTOR_HOST = `${memfreeHost}/vector`;
} else {
throw new Error('Neither MEMFREE_HOST nor VECTOR_HOST is defined');
}
const {
VECTOR_INDEX_HOST: indexHost,
VECTOR_HOST: vectorHost,
MEMFREE_HOST: memfreeHost,
} = process.env;

// Set VECTOR_INDEX_HOST with precedence
export let VECTOR_INDEX_HOST = indexHost || vectorHost || (memfreeHost ? `${memfreeHost}/vector` : '');
if (!VECTOR_INDEX_HOST) throw new Error('VECTOR_INDEX_HOST, VECTOR_HOST, or MEMFREE_HOST must be defined.');

// Set VECTOR_HOST with precedence
export let VECTOR_HOST = vectorHost || (memfreeHost ? `${memfreeHost}/vector` : '');
if (!VECTOR_HOST) throw new Error('MEMFREE_HOST or VECTOR_HOST must be defined.');

// Auth
export const AUTH_GOOGLE_ID = process.env.AUTH_GOOGLE_ID || '';
Expand Down
Loading