.env
This commit is contained in:
29
src/index.ts
29
src/index.ts
@@ -23,6 +23,7 @@ import {
|
||||
} from "node-appwrite";
|
||||
import { readFileSync, existsSync } from "fs";
|
||||
import { join } from "path";
|
||||
import * as dotenv from "dotenv";
|
||||
|
||||
interface AppwriteConfig {
|
||||
projectId: string;
|
||||
@@ -58,25 +59,25 @@ class AppwriteMCPServer {
|
||||
}
|
||||
|
||||
private loadConfig(): void {
|
||||
const configPath = join(process.cwd(), "appwrite-config.json");
|
||||
// Load environment variables from .env file in current working directory
|
||||
dotenv.config({ path: join(process.cwd(), '.env') });
|
||||
|
||||
if (!existsSync(configPath)) {
|
||||
console.error("Appwrite configuration file not found. Please create appwrite-config.json");
|
||||
const projectId = process.env.APPWRITE_PROJECT_ID;
|
||||
const apiEndpoint = process.env.APPWRITE_API_ENDPOINT;
|
||||
const apiKey = process.env.APPWRITE_API_KEY;
|
||||
|
||||
if (!projectId || !apiEndpoint || !apiKey) {
|
||||
console.error("Appwrite configuration missing. Please create a .env file with APPWRITE_PROJECT_ID, APPWRITE_API_ENDPOINT, and APPWRITE_API_KEY");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const configData = readFileSync(configPath, "utf-8");
|
||||
this.config = JSON.parse(configData);
|
||||
|
||||
if (!this.config?.projectId || !this.config?.apiEndpoint || !this.config?.apiKey) {
|
||||
throw new Error("Missing required configuration fields");
|
||||
}
|
||||
this.config = {
|
||||
projectId,
|
||||
apiEndpoint,
|
||||
apiKey
|
||||
};
|
||||
|
||||
this.initializeAppwrite();
|
||||
} catch (error) {
|
||||
console.error("Error loading Appwrite configuration:", error);
|
||||
}
|
||||
this.initializeAppwrite();
|
||||
}
|
||||
|
||||
private initializeAppwrite(): void {
|
||||
|
||||
Reference in New Issue
Block a user