51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
const { stripEnvQuotes } = require('../utils/security');
|
|
|
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
const port = process.env.PORT || 3001;
|
|
const jwtSecret = process.env.JWT_SECRET || (isProduction ? null : 'fasto_dev_secret_change_me');
|
|
|
|
if (!jwtSecret) {
|
|
throw new Error('JWT_SECRET is required in production.');
|
|
}
|
|
|
|
const allowedOrigins = (process.env.CORS_ORIGIN || '')
|
|
.split(',')
|
|
.map(origin => origin.trim())
|
|
.filter(Boolean);
|
|
|
|
const smtp = {
|
|
host: process.env.SMTP_HOST || 'mail.blyzer.com.br',
|
|
port: parseInt(process.env.SMTP_PORT, 10) || 587,
|
|
user: stripEnvQuotes(process.env.SMTP_USER || 'nao-responda@blyzer.com.br'),
|
|
pass: stripEnvQuotes(process.env.SMTP_PASS || ''),
|
|
debug: process.env.SMTP_DEBUG === 'true',
|
|
};
|
|
|
|
const getBaseUrl = (req) => {
|
|
if (process.env.APP_URL) return process.env.APP_URL;
|
|
|
|
const host = req ? (req.get('host') || 'localhost:3001') : 'localhost:3001';
|
|
const protocol = (req && (req.protocol === 'https' || req.get('x-forwarded-proto') === 'https')) ? 'https' : 'http';
|
|
|
|
if (isProduction && !host.includes('localhost')) {
|
|
return `https://${host}`;
|
|
}
|
|
return `${protocol}://${host}`;
|
|
};
|
|
|
|
const getStartupBaseUrl = () => {
|
|
if (process.env.APP_URL) return process.env.APP_URL;
|
|
if (isProduction) return 'https://fasto.blyzer.com.br';
|
|
return 'http://localhost:3001';
|
|
};
|
|
|
|
module.exports = {
|
|
allowedOrigins,
|
|
getBaseUrl,
|
|
getStartupBaseUrl,
|
|
isProduction,
|
|
jwtSecret,
|
|
port,
|
|
smtp,
|
|
};
|