Skip to content

Commit

Permalink
fix: switch to use folder for config
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushSehrawat committed Nov 1, 2024
1 parent d7d4789 commit 7f502e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ vite.config.ts.timestamp-*
/.vs
/package-lock.json
.vscode
server-config.json
/config
11 changes: 9 additions & 2 deletions src/lib/serverConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import fs from 'fs/promises';
import path from 'path';

const CONFIG_FILE = path.join(process.cwd(), 'server-config.json');
const CONFIG_DIR = path.join(process.cwd(), 'config');
const CONFIG_FILE = path.join(CONFIG_DIR, 'server.json');

interface ServerConfig {
backendUrl: string;
Expand All @@ -18,5 +19,11 @@ export async function getServerConfig(): Promise<ServerConfig | null> {
}

export async function setServerConfig(config: ServerConfig): Promise<void> {
await fs.writeFile(CONFIG_FILE, JSON.stringify(config, null, 2));
try {
await fs.mkdir(CONFIG_DIR, { recursive: true });
await fs.writeFile(CONFIG_FILE, JSON.stringify(config, null, 2));
} catch (error) {
console.error('Failed to set server config:', error);
throw error;
}
}

0 comments on commit 7f502e7

Please sign in to comment.