- Added a Chatbot component to the dashboard for user interaction and support. - Created a README for the Chatbot detailing setup, features, and usage instructions. - Introduced environment variables for secure API key management. - Updated app.js to include the Chatbot component. - Implemented a configuration server to serve API keys securely. - Enhanced styles for the Chatbot interface to improve user experience.
49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Simple script to replace environment variable placeholders in frontend code
|
|
* This is a development convenience - in production, use proper build tools
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
require('dotenv').config();
|
|
|
|
const CHATBOT_FILE = path.join(__dirname, 'Chatbot.js');
|
|
const ENV_FILE = path.join(__dirname, '.env');
|
|
|
|
// Read the current Chatbot.js file
|
|
let chatbotContent = fs.readFileSync(CHATBOT_FILE, 'utf8');
|
|
|
|
// Read the .env file
|
|
let envContent = fs.readFileSync(ENV_FILE, 'utf8');
|
|
|
|
// Extract the API key from .env
|
|
const apiKeyMatch = envContent.match(/OPENROUTER_API_KEY=(.+)/);
|
|
if (!apiKeyMatch) {
|
|
console.error('❌ OPENROUTER_API_KEY not found in .env file');
|
|
process.exit(1);
|
|
}
|
|
|
|
const actualApiKey = apiKeyMatch[1].trim();
|
|
|
|
// Replace the placeholder with the actual API key
|
|
const updatedContent = chatbotContent.replace(
|
|
/OPENROUTER_API_KEY: ['"]YOUR_API_KEY_HERE['"]/,
|
|
`OPENROUTER_API_KEY: '${actualApiKey}'`
|
|
);
|
|
|
|
// Write the updated file
|
|
fs.writeFileSync(CHATBOT_FILE, updatedContent);
|
|
|
|
console.log('✅ API key successfully injected into Chatbot.js');
|
|
console.log('🔒 Remember: This is for development only. Use secure methods in production.');
|
|
|
|
// Also update the hardcoded key in the fetch request
|
|
const fetchUpdatedContent = updatedContent.replace(
|
|
/`Bearer \$\{config\.OPENROUTER_API_KEY\}`/g,
|
|
`\`Bearer \${config.OPENROUTER_API_KEY}\``
|
|
);
|
|
|
|
fs.writeFileSync(CHATBOT_FILE, fetchUpdatedContent);
|
|
console.log('✅ Chatbot.js updated with secure API key reference');
|