94 lines
No EOL
4 KiB
JavaScript
94 lines
No EOL
4 KiB
JavaScript
const dotenv = require('dotenv');
|
|
|
|
// Load environment variables
|
|
dotenv.config();
|
|
|
|
const config = {
|
|
// Server configuration
|
|
port: process.env.PORT || 4000,
|
|
nodeEnv: process.env.NODE_ENV || 'development',
|
|
environment: process.env.ENVIRONMENT || 'beta',
|
|
|
|
// Database configuration
|
|
db: {
|
|
host: process.env.DB_HOST || 'db',
|
|
user: process.env.DB_USER || 'postgres',
|
|
password: process.env.DB_PASSWORD || 'postgres',
|
|
database: process.env.DB_NAME || 'ecommerce',
|
|
port: process.env.DB_PORT || 5432
|
|
},
|
|
|
|
// Email configuration
|
|
email: {
|
|
host: process.env.EMAIL_HOST || 'smtp.postmarkapp.com',
|
|
port: process.env.EMAIL_PORT || 587,
|
|
user: process.env.EMAIL_USER || '03c638d8-4a04-9be6',
|
|
pass: process.env.EMAIL_PASS || '03c638d8-4a04-9be6',
|
|
reply: process.env.EMAIL_REPLY || 'noreply@2many.ca'
|
|
},
|
|
|
|
// Payment configuration
|
|
payment: {
|
|
stripeEnabled: process.env.STRIPE_ENABLED === 'true',
|
|
stripePublicKey: process.env.STRIPE_PUBLIC_KEY || '',
|
|
stripeSecretKey: process.env.STRIPE_SECRET_KEY || '',
|
|
stripeWebhookSecret: process.env.STRIPE_WEBHOOK_SECRET || ''
|
|
},
|
|
|
|
// Site configuration (domain and protocol based on environment)
|
|
site: {
|
|
domain: process.env.ENVIRONMENT === 'prod' ? 'rocks.2many.ca' : 'localhost:3000',
|
|
protocol: process.env.ENVIRONMENT === 'prod' ? 'https' : 'http',
|
|
apiDomain: process.env.ENVIRONMENT === 'prod' ? 'api.rocks.2many.ca' : 'localhost:4000'
|
|
}
|
|
};
|
|
|
|
// This function will be called after loading settings from DB
|
|
// to override config values with DB values
|
|
config.updateFromDatabase = (settings) => {
|
|
if (!settings) return;
|
|
|
|
// Update email settings if they exist in DB
|
|
const emailSettings = settings.filter(s => s.category === 'email');
|
|
if (emailSettings.length > 0) {
|
|
const smtpHost = emailSettings.find(s => s.key === 'smtp_host');
|
|
const smtpPort = emailSettings.find(s => s.key === 'smtp_port');
|
|
const smtpUser = emailSettings.find(s => s.key === 'smtp_user');
|
|
const smtpPass = emailSettings.find(s => s.key === 'smtp_password');
|
|
const smtpReply = emailSettings.find(s => s.key === 'smtp_from_email');
|
|
|
|
if (smtpHost && smtpHost.value) config.email.host = smtpHost.value;
|
|
if (smtpPort && smtpPort.value) config.email.port = parseInt(smtpPort.value, 10);
|
|
if (smtpUser && smtpUser.value) config.email.user = smtpUser.value;
|
|
if (smtpPass && smtpPass.value) config.email.pass = smtpPass.value;
|
|
if (smtpReply && smtpReply.value) config.email.reply = smtpReply.value;
|
|
}
|
|
|
|
// Update payment settings if they exist in DB
|
|
const paymentSettings = settings.filter(s => s.category === 'payment');
|
|
if (paymentSettings.length > 0) {
|
|
const stripeEnabled = paymentSettings.find(s => s.key === 'stripe_enabled');
|
|
const stripePublic = paymentSettings.find(s => s.key === 'stripe_public_key');
|
|
const stripeSecret = paymentSettings.find(s => s.key === 'stripe_secret_key');
|
|
const stripeWebhook = paymentSettings.find(s => s.key === 'stripe_webhook_secret');
|
|
|
|
if (stripeEnabled && stripeEnabled.value) config.payment.stripeEnabled = stripeEnabled.value === 'true';
|
|
if (stripePublic && stripePublic.value) config.payment.stripePublicKey = stripePublic.value;
|
|
if (stripeSecret && stripeSecret.value) config.payment.stripeSecretKey = stripeSecret.value;
|
|
if (stripeWebhook && stripeWebhook.value) config.payment.stripeWebhookSecret = stripeWebhook.value;
|
|
}
|
|
|
|
// Update site settings if they exist in DB
|
|
const siteSettings = settings.filter(s => s.category === 'site');
|
|
if (siteSettings.length > 0) {
|
|
const siteDomain = siteSettings.find(s => s.key === 'site_domain');
|
|
const siteProtocol = siteSettings.find(s => s.key === 'site_protocol');
|
|
const siteApiDomain = siteSettings.find(s => s.key === 'site_api_domain');
|
|
|
|
if (siteDomain && siteDomain.value) config.site.domain = siteDomain.value;
|
|
if (siteProtocol && siteProtocol.value) config.site.protocol = siteProtocol.value;
|
|
if (siteApiDomain && siteApiDomain.value) config.site.apiDomain = siteApiDomain.value;
|
|
}
|
|
};
|
|
|
|
module.exports = config; |