Try
dfssdfsfdsf
This commit is contained in:
@@ -3,20 +3,47 @@
|
||||
* Centralized configuration management
|
||||
*/
|
||||
|
||||
import { readFileSync, existsSync } from 'fs'
|
||||
import { dirname, join } from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { log } from '../middleware/logger.mjs'
|
||||
|
||||
const _configDir = dirname(fileURLToPath(import.meta.url))
|
||||
const _repoRoot = join(_configDir, '..', '..')
|
||||
|
||||
/** Default dev API port from repo root `mailflow.dev.port.json` (avoids clashes with other apps on 3000). */
|
||||
function readDevPortFromFile() {
|
||||
try {
|
||||
const f = join(_repoRoot, 'mailflow.dev.port.json')
|
||||
if (!existsSync(f)) return 3030
|
||||
const j = JSON.parse(readFileSync(f, 'utf8'))
|
||||
const p = parseInt(String(j.port), 10)
|
||||
return Number.isFinite(p) && p > 0 ? p : 3030
|
||||
} catch {
|
||||
return 3030
|
||||
}
|
||||
}
|
||||
|
||||
const nodeEnv = process.env.NODE_ENV || 'development'
|
||||
const listenPort = process.env.PORT
|
||||
? parseInt(process.env.PORT, 10)
|
||||
: nodeEnv === 'production'
|
||||
? 3000
|
||||
: readDevPortFromFile()
|
||||
const defaultLocalBase = `http://localhost:${listenPort}`
|
||||
|
||||
/**
|
||||
* Environment configuration
|
||||
*/
|
||||
export const config = {
|
||||
// Server
|
||||
port: parseInt(process.env.PORT || '3000', 10),
|
||||
nodeEnv: process.env.NODE_ENV || 'development',
|
||||
isDev: process.env.NODE_ENV !== 'production',
|
||||
isProd: process.env.NODE_ENV === 'production',
|
||||
port: listenPort,
|
||||
nodeEnv,
|
||||
isDev: nodeEnv !== 'production',
|
||||
isProd: nodeEnv === 'production',
|
||||
|
||||
// URLs
|
||||
baseUrl: process.env.BASE_URL || 'http://localhost:3000',
|
||||
baseUrl: process.env.BASE_URL || defaultLocalBase,
|
||||
frontendUrl: process.env.FRONTEND_URL || 'http://localhost:5173',
|
||||
|
||||
// Appwrite
|
||||
@@ -42,14 +69,14 @@ export const config = {
|
||||
google: {
|
||||
clientId: process.env.GOOGLE_CLIENT_ID,
|
||||
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
||||
redirectUri: process.env.GOOGLE_REDIRECT_URI || 'http://localhost:3000/api/oauth/gmail/callback',
|
||||
redirectUri: process.env.GOOGLE_REDIRECT_URI || `${defaultLocalBase}/api/oauth/gmail/callback`,
|
||||
},
|
||||
|
||||
// Microsoft OAuth
|
||||
microsoft: {
|
||||
clientId: process.env.MICROSOFT_CLIENT_ID,
|
||||
clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
|
||||
redirectUri: process.env.MICROSOFT_REDIRECT_URI || 'http://localhost:3000/api/oauth/outlook/callback',
|
||||
redirectUri: process.env.MICROSOFT_REDIRECT_URI || `${defaultLocalBase}/api/oauth/outlook/callback`,
|
||||
},
|
||||
|
||||
// Mistral AI
|
||||
@@ -63,9 +90,19 @@ export const config = {
|
||||
max: parseInt(process.env.RATE_LIMIT_MAX || '100', 10),
|
||||
},
|
||||
|
||||
// CORS
|
||||
// CORS (Dev: localhost + 127.0.0.1 für Vite, Browser ruft API oft direkt auf 127.0.0.1:PORT)
|
||||
cors: {
|
||||
origin: process.env.CORS_ORIGIN || process.env.FRONTEND_URL || 'http://localhost:5173',
|
||||
origin:
|
||||
process.env.NODE_ENV === 'production'
|
||||
? process.env.CORS_ORIGIN || process.env.FRONTEND_URL || 'http://localhost:5173'
|
||||
: [
|
||||
process.env.CORS_ORIGIN,
|
||||
process.env.FRONTEND_URL,
|
||||
'http://localhost:5173',
|
||||
'http://127.0.0.1:5173',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.filter((o, i, a) => a.indexOf(o) === i),
|
||||
credentials: true,
|
||||
},
|
||||
|
||||
@@ -79,11 +116,15 @@ export const config = {
|
||||
/** Highest product tier (admin comped plan, PLANS key in stripe.mjs). Optional env: TOP_SUBSCRIPTION_PLAN */
|
||||
topSubscriptionPlan: (process.env.TOP_SUBSCRIPTION_PLAN || 'business').trim().toLowerCase(),
|
||||
|
||||
// Admin: comma-separated list of emails with admin rights (e.g. support)
|
||||
adminEmails: (process.env.ADMIN_EMAILS || '')
|
||||
.split(',')
|
||||
.map((e) => e.trim().toLowerCase())
|
||||
.filter(Boolean),
|
||||
// Admin: comma-separated list of emails with admin rights (e.g. support).
|
||||
// support@webklar.com is always included; env adds more.
|
||||
adminEmails: (() => {
|
||||
const fromEnv = (process.env.ADMIN_EMAILS || '')
|
||||
.split(',')
|
||||
.map((e) => e.trim().toLowerCase())
|
||||
.filter(Boolean)
|
||||
return [...new Set(['support@webklar.com', ...fromEnv])]
|
||||
})(),
|
||||
|
||||
// Gitea Webhook (Deployment) — trim: trailing newlines in .env break HMAC/Bearer match
|
||||
gitea: (() => {
|
||||
|
||||
Reference in New Issue
Block a user